Difference between revisions of "Configure Apache load balancer with mod proxy"
(→Define Apache Load-balancer) |
(→Configure Tomcat) |
||
Line 45: | Line 45: | ||
== Configure Tomcat == | == Configure Tomcat == | ||
− | |||
− | + | <source lang="xml"> | |
− | + | <Connector port="8082" protocol="HTTP/1.1" | |
− | + | connectionTimeout="20000" | |
− | + | redirectPort="8445" | |
− | <source lang=" | + | URIEncoding="UTF-8" server="Undisclosed/8.41" proxyName="ldproxy.org" proxyPort="80" /> |
− | <Connector port=" | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> | ||
− | |||
− |
Revision as of 10:41, 27 June 2019
Server setup
The layout may look something like this (we will refer to these names through the rest of the guide).
Define Apache Load-balancer
This server will handle all HTTP requests from site visitors. As you might see, this means even though you run a load balanced system, using only a single load balancer means you still have a SPOF (single point of failure). It is also possible to configure an environment where yet another server will act as the fail-over load-balancer if the first one fails, but this is outside the scope of this guide.
To set up our load-balancer, we use the Apache web-server and its modules mod_proxy and mod_proxy_balancer. These are part of most of the Apache web-server distributions.
First, create a virtual host handling the requests for your domain: ldproxy.org
<VirtualHost *:80>
ServerName ldproxy.org
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ProxyRequests Off
ProxyPreserveHost On
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy balancer://mycluster>
BalancerMember "http://eva00:9080" route=1
BalancerMember "http://192.168.2.11:8080" route=2
ProxySet lbmethod=byrequests
ProxySet stickysession=ROUTEID
</Proxy>
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
ErrorLog ${APACHE_LOG_DIR}/proxy-error.log
CustomLog ${APACHE_LOG_DIR}/proxy-access.log combined
</VirtualHost>
Configure Tomcat
<Connector port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8445"
URIEncoding="UTF-8" server="Undisclosed/8.41" proxyName="ldproxy.org" proxyPort="80" />