Using an Apache VirtualHost to access a Node JS instance on the same server

apache-2.2node.jsvirtualhost

I am using VirtualHosts to allow access to various domains and subdomians of my site on the same Apache server. Along the lines of:

<VirtualHost *:80>
    DocumentRoot /var/www/site
    ServerName example.com
</VirtualHost>

I want to have a specific subdomain pointing to a NodeJS server on the same server. I know I could use ProxyPass to forward to a different server, is there a similar way to do this with the same machine?

I assume I would have the Node server running on a port other than 80.

Best Answer

Lets assume,

Node.js running on http://localhost:8000

<VirtualHost node.example.com:80>   
    ServerName node.example.com
    # with optional timeout settings  
    ProxyPass / http://localhost:8000/ connectiontimeout=5 timeout=30
</VirtualHost>

I hope that helps

Related Topic