Apache and Node.js on the Same Server

前端 未结 10 1548
青春惊慌失措
青春惊慌失措 2020-11-22 06:11

I want to use Node because it\'s swift, uses the same language I am using on the client side, and it\'s non-blocking by definition. But the guy who I hired to write the pro

10条回答
  •  失恋的感觉
    2020-11-22 06:59

    I was looking for the same information. Finally found the answer from the link on the answer above by @Straseus

    http://arguments.callee.info/2010/04/20/running-apache-and-node-js-together/

    Here is the final solution to run apache website on port 80, node js service on port 8080 and use .htaccess RewriteRule

    In the DocumentRoot of the apache website, add the following:

    Options +FollowSymLinks -MultiViews
    
    
    
    RewriteEngine on
    
    # Simple URL redirect:
    RewriteRule ^test.html$ http://arguments.callee.info:8000/test/ [P]
    
    # More complicated (the user sees only "benchmark.html" in their address bar)
    RewriteRule ^benchmark.html$ http://arguments.callee.info:8000/node?action=benchmark [P]
    
    # Redirect a whole subdirectory:
    RewriteRule ^node/(.*) http://arguments.callee.info:8000/$1 [P]
    

    For the directory level redirect, the link above suggested (.+) rule, which requires one or more character after the 'node/'. I had to convert it to (.*) which is zero or more for my stuff to work.

    Thanks a lot for the link @Straseus

提交回复
热议问题