Port based reverse proxy in Apache Web server

apache-2.2apache-2.4mod-proxyPROXYreverse-proxy

I have two web applications http://app1:8080 and http://app2:3000 running on two different ports and different machines. I have to pass the applications traffic through Apache web server, http://myapp.

Now, we can configure apache webserver as reverse proxy based by mounting application to specific location.
For example,

ProxyPass /app1/ http://app1:8080/
ProxyPass /app2/ http://app2:3000/

ProxyPassReverse /app1/ http://app1:8080/
ProxyPassReverse /app2/ http://app2:3000/

After this mapping, http://myapp/app1 points to http://app1:8080 and
http://myapp/app2 points to http://app2:3000.

But, my requirement is http://myapp:8080 should point to http://app1:8080 and
http://myapp:3000 should point to http://app2:3000.
Kindly guide me how to reverse proxy the traffic on the basis of ports in apache web server.

Best Answer

You would need to create two separate Virtual Hosts, with the different ports you want.

You would need

<VirtualHost *:8080>
    ...
</VirtualHost>

<VirtualHost *:3000>
    ...
</VirtualHost>

You also will need to set Apache Listen directives for both those ports

Listen 8080, 3000
Related Topic