Configure Apache load balancer with mod proxy

From LogicalDOC Community Wiki
Revision as of 11:08, 27 June 2019 by Blucecio (talk | contribs) (Define Apache Load-balancer)
Jump to navigationJump to search

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:

<VirtualHost *:80>


  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html

  ProxyRequests Off
  ProxyPreserveHost On

  <Proxy balancer://mycluster>
        BalancerMember "http://eva00:9080" route=1
        BalancerMember "" route=2

        ProxySet lbmethod=byrequests
        ProxySet stickysession=ROUTEID

  ProxyPass / balancer://mycluster/
  ProxyPassReverse / balancer://mycluster/

  ErrorLog ${APACHE_LOG_DIR}/proxy-error.log
  CustomLog ${APACHE_LOG_DIR}/proxy-access.log combined


The load balancer nodes are two LogicalDOC servers that are accessed by IP and by hostname (eva00), of course the Apache server must be able to resolve the hostname. Furthermore we can note that the Apache server inserts a Cookie ROUTEID to make sticky sessions and redirect all subsequent requests to the same LogicalDOC node of the cluster

Configure Tomcat

You need to change the configuration of the Tomcat in LogicalDOC. Generally it is a matter of modifying the file server.xml located in the /tomcat/conf folder

Tomcat config: LOGICALDOC_HOME/tomcat/conf/server.xml

In this file we are going to add the proxyName and proxyPort attributes to the Connector element

    <Connector port="8082" protocol="HTTP/1.1"
               URIEncoding="UTF-8" server="Undisclosed/8.41" proxyName="" proxyPort="80" />

The proxyName will cause servlets inside this web application to think that all proxied requests were directed to on port 80

Additional information