I am trying to run a Node js app on port 8000, and have Apache 2.4.7 proxy a subdomain to that port on localhost. I'm able to get the node app served as a page ( http://example.com/nodeapp ) using a single VirtualHost, using a sites-enabled conf file like the one below:
<VirtualHost *:80>
ServerName example.com
ServerAlias "www.example.com"
DocumentRoot "/var/www/html"
ProxyPass "/nodeapp" "http://localhost:8000/"
</VirtualHost>
However, what I really want to do is have the node app run on a subdomain, like http://nodeapp.example.com, and this is where I'm having trouble. I've tried a bunch of different configurations with single and multiple VirtualHosts, but this is what my current one looks like:
<VirtualHost nodeapp.example.com:80>
ServerName "nodeapp.example.com"
# ProxyPreserveHost On
ProxyPass "/" "http://localhost:8000/"
# ProxyPassReverse "/" "http://localhost:8000/"
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias "www.example.com"
DocumentRoot "/var/www/html"
</VirtualHost>
This is based on the question asked here:
Using an Apache VirtualHost to access a Node JS instance on the same server
However, when I go to the subdomain (which I setup on GoDaddy to just forward to the same server IP address), I just get a timeout, and if I look in the apache error log I see some lines like:
[Tue Mar 29 04:53:56.909467 2016] [core:notice] [pid 15912] AH00094: Command line: '/usr/sbin/apache2'
[Tue Mar 29 04:56:33.332390 2016] [proxy:error] [pid 15917] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8000 (localhost) failed
[Tue Mar 29 04:56:33.332441 2016] [proxy:error] [pid 15917] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 60s
I'm really not quite sure where I'm going wrong at this point, but any help would be greatly appreciated!
Best Answer
Here is what I use: