Empowering you to understand your world

How To Run Node.js On The Same Server As Apache

If you need to use Node.js on a server that has Apache installed, you can either run your Node.js application on a different port, or you can use the ‘ProxyPass’ feature in Apache to route requests to your Node app if you want to use the same port.

The first step is to enable the ‘proxy’ and ‘proxy_http’ modules:

sudo a2enmod proxy_http

Then you would add ProxyPass to the end of your ‘apache2.conf’ file as shown below. ‘8080’ is just an example port number that you would change to the one your app uses:

ProxyPass /path_user_will_type_in http://localhost:8080

Note the lack of a trailing slash after the Node app’s address. That means that it will Apache will route users to everything under that path, including your scripts and stylesheets. If you add a trailing slash, it will only route users to the exact URL shown above. This second approach is problematic if your Node app depends on multiple other files such as stylesheets and scripts.

Subscribe to our newsletter
Get notified when new content is published