Send subdomain to node.js Send subdomain to node.js apache apache

Send subdomain to node.js


<VirtualHost *:80>ServerName subdomain.yourdomain.comProxyPreserveHost onProxyPass / http://localhost:8080/</VirtualHost>

Thanks to http://www.chrisshiplet.com/2013/how-to-use-node-js-with-apache-on-port-80/


if socket.io node is running, be sure to enable also few apache mods:

  1. a2enmod proxy
  2. a2enmod proxy_balancer
  3. a2enmod proxy_express
  4. a2enmod proxy_http

in file /etc/apache2/sites-available/chat.example.com.conf


<VirtualHost *:80>    ServerName chat.example.com    <Location "/">        ProxyPreserveHost On        ProxyPass http://localhost:3000/        ProxyPassReverse http://localhost:3000/    </Location></VirtualHost>

then of course service apache2 reload


Let me start from the ground up:

You have a DNS. And a dns server maps one DNS to one IP!

You then have apache running on your computer that listens for connections on port 80 for http:// and on port 443 for https://. http://example/ is actually a request on http://example:80/.

You can't use node.js to listen on the same machine on the same port as apache. That's why using port 8080 is viable.

You can also map the subdomain to a different IP. The only caveat here is that you need to have a public IP Address.