FreeKB - Apache (Web Server) proxy pass setup
Apache (Web Server) - proxy pass setup

Let's say you have an application deployed to an application server, such as Tomcat. One way to serve the 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. 

 

The web server will need to load the mod_proxy.so module for the basic proxy capabilities and the mod_proxy_balancer.so module for load balancing. Additionally, the mod_proxy_http.so module will be needed so that the HTTP protocol can be used. Here is an example of the /opt/Apache/modules directory on one of my Apache servers.

-rwxr-xr-x. 1 nobody nobody 140776 Jan  8  2021 mod_proxy_balancer.so
-rwxr-xr-x. 1 nobody nobody 103056 Jan  8  2021 mod_proxy_http.so
-rwxr-xr-x. 1 nobody nobody 290978 Jan  8  2021 mod_proxy.so

 

Here is an example HTTPD vhosts.conf file with the proxy configurations. In this example, the second field of the ProxyPass line is /sample. This means that when www.example.com/sample is requested, the web server will proxy the request onto http://www.example.com:8080/sample. 

<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 a7460 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |