How to set up Apache webserver proxy in front of Apache Tomcat on Red Hat Linux - LinuxConfig.org

Our objective is to setup Apache httpd to work as a proxy in front of the Apache Tomcat application container.
This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-set-up-apache-webserver-proxy-in-front-of-apache-tomcat-on-red-hat-linux

Hi, I am a newbie in the linux world but with a great desire to learn…I have the following configuration on fedora 22: apache tomcat running in port 8080, apache running in port 80 and also setup squirrellmail with postfix and dovecot which you can access localhost/webmail, everything works independently, and I like to integrate all together. What I need to to do is:

  1. if I do localhost or ipdadress I have to have the tomcat server with a web page running, in other words localhost needs to redirect me to localhost:8080
  2. at the same time if I do localhost/webmail I want to see the squirrellwebmail login screen.

first I used iptables to prerouting everything from port 80 to port 8080 and the tomcat works in the way I want, but with this configuration I cannot access localhost/webmail, for obviously reasons of the prerouting
There is any way I can do this using this proxy setup?
any help really appreciated…

Hi Tigerbengal2009,

Welcome to our forums.

Yes, this is exactly what this proxy setup is for, you can put Apache httpd in front of all of these services. While you can use the ajp module for Tomcat mentioned in this guide, I guess you should use simple http proxy for the webmail access.

Have you tried to setup say, the Apache -> Tomcat proxy to start with?

Thank you sandmann for your response, as I said I am a newbie and apparently does not know basic things, how that http proxy works, where can I find info to explain me to understand it, I tried google it but they mostly go for the ajp approach, can you please point me where to start, or what configuration I have to setup in order to the system to work, I know a lot of try and error has to occur until I find the final solution, but need to do something about it as soon as possible…

Hi Tigerbengal2009,

I would suggest start with the ajp approach for Tomcat, but first I suggest you take the iptables rules that do the prerouting down, so you return to the original state, webmail reachable at localhost/webmail (port 80), and Tomcat reachable on localhost:8080. From there you only need to decide what do you want to proxy from Tomcat trough Apache, and follow the guide accordingly.

Yes I know I have to remove the iptables prerouting in return to the original state…but after that how can I redirect all the traffic going to port 80 to port 8080 where tomcat is awaiting?
as I said before, all the traffic going to port 80 has to be redirected to tomcat which is listening on port 8080.
or it is that this is not possible??? do I have to have apache with static html?, I don’t know maybe I should give up on this, too much time searching , reading and I am at the same loop…

Hi Tigerbengal2009,

You said earlier:

For me this means that you have a service on localhost:80/webmail that you want to reach. You also have service on localhost:8080, which is provided by Tomcat. Now you want to reach both from port 80.
This is not the same as what you say now:

To reach the webmail service, while proxying everything from Tomcat, you need to dedicate a “folder” to Tomcat, let’s say localhost/tomcat-apps, so everything that request something behind this URL will be proxied to Tomcat - so you don’t have to proxy the applications within Tomcat one by one. For this the proxy configuration would be something like this:

<VirtualHost localhost:80>
  ServerName localhost

  ProxyRequests Off
  ProxyPass /tomcat-apps ajp://localhost:8009
  ProxyPassReverse /tomcat-apps ajp://localhost:8009
</VirtualHost>

The port 8009 is no mistake, that is the AJP port Tomcat listens on by default. This way you should reach everything in Tomcat with appended “tomcat-apps” between localhost and the name of the application, for example, the examples application installed in this guide would be reachable with the URL localhost/tomcat-apps/examples.