Tomcat – Run Apache http, Apache tomcat and nodejs on same port

httpdmod-proxynode.jstomcat

I'm a web developer and for a project I need to run tomcat and nodejs without using port.

I've seen some posts about proxy module in httpd, so I've created two virtual hosts as follow :

<VirtualHost *:80>
       ServerName localhost
       # ErrorLog "logs/tomcat-error.log"
       ProxyPreserveHost On
       ProxyPass /tomcat http://localhost:8080/
       ProxyPassReverse /tomcat http://localhost:8080/
</VirtualHost>

<VirtualHost *:80>
      ServerName localhost
      # ErrorLog "logs/nodejs-error.log"
      ProxyPreserveHost On
      ProxyPass /nodejs http://localhost:8000/
      ProxyPassReverse /nodejs http://localhost:8000/
</VirtualHost>

And when I try to access both localhost/nodejs or localhost/tomcat I get a Not Found error.

Can someone explain me why ?

Thanks 😉

Best Answer

The first matched VirtualHost shadows the followings. So the ProxyPass to nodejs is never reached.

You should merge it all as:

<VirtualHost *:80>
   ServerName localhost
   # ErrorLog "logs/tomcat-error.log"

   <Location /tomcat/ >
      ProxyPreserveHost On
      ProxyPass http://localhost:8080/
      ProxyPassReverse http://localhost:8080/
   </Location>

   # ErrorLog "logs/nodejs-error.log"
   <Location /nodejs/ >
      ProxyPreserveHost On
      ProxyPass http://localhost:8000/
      ProxyPassReverse http://localhost:8000/
   </Location>
</VirtualHost>

Have you enabled the proxy and proxy_http modules?

And of course the tomcat and nodejs side should be in-place.