Apache + Node.js + mod_proxy. How to route one domain to :3000 and another to :80


Question

Problem: I need to host a Node-application and a php-application on the same server on different domains.

example.com should use port 80 as normal, but node-example.com should route to port 3000.

Routing ALL traffic from port 80 to 3000 works fine using mod_proxy, thusly:

<VirtualHost *:80>
    ServerAdmin info@node-example.com
    ServerName  node-example.com
    ServerAlias www.node-example.com

    ProxyRequests off

    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>

    <Location />
            ProxyPass http://localhost:3000/
            ProxyPassReverse http://localhost:3000/
    </Location>

</VirtualHost>

This however makes both example.com and node-example.com to point to localhost:3000 and run the Node-app.

Is there a way to keep example.com to point to port 80?

It would also be okay for example.com/old-admin to point to port 80.

1
26
1/10/2013 1:43:04 PM

Just make two <VirtualHost *:80> tags

<VirtualHost *:80>
    ServerAdmin info@node-example.com
    ServerName www.node-example.com

    ProxyRequests off

    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>

    <Location />
            ProxyPass http://localhost:3000/
            ProxyPassReverse http://localhost:3000/
    </Location>

</VirtualHost>
<VirtualHost *:80>
    ServerAdmin info@node-example.com
    ServerName  node-example.com    

    ProxyRequests off

    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>

    <Location />
            ProxyPass http://localhost:80/
            ProxyPassReverse http://localhost:80/
    </Location>

</VirtualHost>

It should work that way ;)

Or if your localhost:80 app isn't node you can remove <Proxy *> & <Location /> tags for that target and replace it with DocumentRoot /var/www/node-example.com - your static path to index.html

34
1/10/2013 2:21:16 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon