How to run Apache And Nodejs together?

Today i was facing the problem to run nodejs on a server which is already running apache as webserver. So i had to choose a different port for the node app, but i didn’t want to enter an url like this http://nodeapp.domain.com:port. So how can I achieve this, without entering the port at the end of the domain?
1 answer

How to run Apache And Nodejs Together without entering a port number

You have to redirect http://nodeapp.domain.com to http://nodeapp.domain.com:port. This can easily be done by using an http proxy. All you need to do is:

  • Enable the proxy by executing:
    >> sudo a2enmod proxy
    >> sudo a2enmod proxy_http
  • Add the following lines to your /etc/apache2/sites-available/default

    ServerName nodeapp.domain.com
    ProxyRequests off

    Order deny,allow
    Allow from all

    ProxyPass http://localhost:port/
    ProxyPassReverse http://localhost:port/

  • That’s all you have to do in order to setup your node app besides an apache webserver.
    Finally you only have to start your node app:

    >> sudo node nodefile.js //don't forget the "sudo" command otherwise you may get an error (503)

[I had this problem a while ago and solved it this way. You can find my original blog post at http://www.manuelmertl.com/running-apache-and-nodejs-together/]