How to configure HTTPD to proxy pass a Tomcat application

Home > Search > How-to
  by

One way to serve a Tomcat application is to have clients request the application directly from the Tomcat server.

 

In this example, the client requests www.example.com:8080/sample direct from Tomcat, and then Tomcat sends the application to the client.

 

A web server can be configured as a proxy server, so that the clients will request the Tomcat application from the web server, and then the web server will get the application from Tomcat, and the web server will send the Tomcat application to the client. 

 

As an example, if the webserver is HTTPD, you would add the following markup to the server.xml file.

<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

 

Assuming HTTPD is configured to use virtual hosts, add Proxy and ProxyPass to the /etc/httpd/sites-enabled/vhosts.conf file. The second field of the ProxyPass line is /sample. This means that when www.example.com/sample is requested, the web server will request http://www.example.com:8080/sample from Tomcat. 

<VirtualHost *:80>
   ServerName www.example.com
   DocumentRoot "/var/www/site1"
 
   <Proxy *>
     AddDefaultCharset Off
     Order deny,allow
     Allow from all
   </Proxy>
 
   ProxyPass /sample http://www.example.com:8080/sample
   ProxyPassReverse /sample http://www.example.com:8080/sample

</VirtualHost>

 

Now, the Tomcat application can be produced by navigating to www.example.com/sample.

 


Muliple JVMs on Tomcat

Another advantages of using a proxy pass is being able to route requests to a number of different Tomcat application servers. For example, let's say you have a single Tomcat server with three different JVMs, each listening on their own port.

http://www.example.com:8080/jvm1
http://www.example.com:8081/jvm2
http://www.example.com:8082/jvm2

 

A single web server can proxy requests to each JVM.

ProxyPass /app1 http://www.example.com:8080/jvm1
ProxyPass /app2 http://www.example.com:8081/jvm2
ProxyPass /app3 http://www.example.com:8082/jvm3

 


Multiple Tomcat

A proxy pass can also route requests to different Tomcat servers. For example, let's say you've three different Tomcat servers.

http://www.server1.com:8080/jvm
http://www.server2.com:8080/jvm
http://www.server3.com:8080/jvm

 

A single web server can proxy requests to each JVM.

ProxyPass /app1 http://www.server1.com:8080/jvm
ProxyPass /app2 http://www.server2.com:8080/jvm
ProxyPass /app3 http://www.server3.com:8080/jvm

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments