I have an Amazon cloud running which is hosting two tomcat instances (ports 8080 and 8081) with each tomcat running a web application (foo and bar) for different customers.
However I am having a problem trying to get the port redirect working correctly.
I want users who come to my website at
www.foo.com to be redirected automagically
www.foo.com:8080/foo_app and users who come to my website at
www.bar.com to be redirected automagically to
But, I also want the port numbers to NOT be part of the URL. This is vitally important
since most of the users are in environments where they cannot navigate to
www.bar.com:8180 and can only communicate on port 80.
So anyone who types in
www.bar.com/bar_app should be redirected to
www.bar.com:8081/bar_app but the URL still must be
The way I have attempted to achieve this is to do the following:
I used the following command to map any communication on port 80 to port 8080
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
This is great for the foo users but the bar users are also getting re-directed. Is it possible to make this iptable mapping only applicable for certain "servers" ?
I have also added entries into
to allow mapping from my server to the actual webapp
<VirtualHost *:80> ProxyPreserveHost On ProxyPass / http://22.214.171.124:8080/foo_app ProxyPassReverse / http://126.96.36.199:8080/foo_app ServerName www.foo.com ServerAlias www.foo.com </VirtualHost> <VirtualHost *:80> ProxyPreserveHost On ProxyPass / http://188.8.131.52:8180/bar_app ProxyPassReverse / http://184.108.40.206:8180/bar_app ServerName www.bar.com ServerAlias www.bar.com </VirtualHost>
I would greatly appreciate help from anyone who can advise on an approach to take.