The Apache 2.2 webserver has a module for proxiing AJP requests (mod_proxy_ajp). This module is delivered with the Apache webserver by default.
Activating modules
The following modules must be enabled to use the AJP proxy functionallity:
- mod_proxy
- mod_proxy_ajp
- mod_proxy_balancer
To activate the modules uncomment the following lines in your httpd.conf configuration file (e.g. /opt/apache/conf/httpd.conf):
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
Configuring modules
To configure the modules we create a new configuration file conf/ajp_proxy.conf in the apache directory and add the following line to our httpd.conf file:
Include conf/ajp_proxy.conf
First of all we put all configuration directives in <IfModule/> blocks to ensure that all needed modules are loaded:
<IfModule mod_proxy> <IfModule mod_proxy_ajp> <IfModule mod_proxy_balancer> # configuration of AJP proxy </IfModule> </IfModule> </IfModule>
Creating Load Balancer Cluster
The load balancer cluster is created with the ProxyPass directive. The syntax for this directive is
ProxyPass <path> balancer://<name-of-cluster> <options>
The <path> argument stays for the logical path on the apache server, <name-of-cluster> for the name of your cluster and <options> for the options for this load balacer cluster (see documentation for description of options).
Example:
ProxyPass /myapp balancer://mycluster/myapp stickysession=JSESSIONID nofailover=On
In the next step we must define the workers for our cluster and your application server must support the JServ AJP protocol, e.g. Tomcat. For glassfish aka Sun Java System Application Server see my mod_jk tutorial for implementing the JServ protocol into the server.
The workers are definded into a <Proxy/> directive. The syntax for this directive is
<Proxy balancer://<name-of-cluster> BalancerMember ajp:<hostname>:<port> <options> </Proxy>
You can define multiple workers in one proxy directive.
Example for two worker nodes:
<Proxy balancer://mycluster> BalancerMember ajp://node1.mydomain.com:8009 route=node1 BalancerMember ajp://node2.mydomain.com:8009 route=node2 </Proxy>