
An Apache HTTP web server can be configured with proxy modules which will allow the HTTP web server to "proxy" requests onto some other system. For example, a request coming into the web server could be proxy onto a different HTTP web server. Or the request could be proxy to an application server, such as JBoss or Tomcat or WebSphere.
The Apache HTTP web server will need to load the mod_proxy module which means placing the mod_proxy.so file in the "modules" directory of the web server, such as /opt/webserver/modules/mod_proxy.so.
Additionally, mod_proxy_http and/or mod_proxy_ftp are needed to proxy HTTP and FTP requests.
- mod_proxy_http - To proxy HTTP requests
- mod_proxy_ftp - To proxy FTP requests
Additionally, if the web server will be load balancing requests across two or more Tomcat application servers, then the mod_proxy_balancer module will also need to be placed in the "modules" directory of the web server and one or more of the mod_lbmethod_by modules must also be placed in the "modules" directory of the web server as at least one of these modules is required for load balancing scheduling.
- mod_proxy_balancer - To load balance requests to two or more target systems
- mod_lbmethod_bybusyness - Load Balancing based on pending requests
- mod_lbmethod_byrequests - Load Balancing based on the number of requests
- mod_lbmethod_bytraffic - Load Balancing based on the volume of traffic
- mod_lbmethod_heartbeat - Load Balancing based on heartbeat traffic count
You may need to install Apache with the --enable-proxy and --enable-proxy-balancer flags to get the latest stable mod_proxy and mod_lbmethod modules. Check out my article on Installing Apache on Linux.
Here is an example of a web server configuration file (e.g. httpd.conf) with the proxy configurations. In this example, the second field of the ProxyPass line is /sample. This means that when http://<web server hostname or IP address>/sample is requested, the web server will proxy the request onto http://www.example.com:8080/sample.
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
LoadModule lbmethod_byheartbeat_module modules/mod_lbmethod_byheartbeat.so
<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>
~]# <web_server_root>/bin/apachectl -M
Loaded Modules:
proxy_module (shared)
proxy_http_module (shared)
proxy_balancer_module (shared)
lbmethod_bybusyness_module (shared)
lbmethod_byrequests_module (shared)
lbmethod_bytraffic_module (shared)
lbmethod_byheartbeat_module (shared)
If, for example, www.example.com/sample is supposed to return a Tomcat app, if you get the Tomcat app, then the proxy is working.
Optionally, the AllowCONNECT directive can be used to define the ports that are allowed.
AllowCONNECT 80
<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>
Muliple Backend Systems and Services
Another advantage of using a proxy pass is being able to route requests to a number of different backends. For example, let's say you have different backend services listening on their own port.
http://www.example.com:8080/
http://www.example.com:8081/
http://www.example.com:8082/
A single web server can proxy requests to each backend service.
ProxyPass /service1 http://www.example.com:8080/
ProxyPass /service2 http://www.example.com:8081/
ProxyPass /service3 http://www.example.com:8082/
A proxy pass can also route requests to different backend systems.
ProxyPass /backend1 http://www.server1.com:8080/
ProxyPass /backend2 http://www.server2.com:8080/
ProxyPass /backend3 http://www.server3.com:8080/
Did you find this article helpful?
If so, consider buying me a coffee over at