Apache load balancer: Redirections pwned
By Kai Seidler on Oct 28, 2009
HTTP load balancers have one natural enemy: redirections. For example, a "trailing slash" redirect is issued when the server receives a request for a URL http://servername/dir where dir is a directory. In such a case the server redirects the browser to http://servername/dirname/ (including the trailing slash):
# lynx -mime_header http://loadbalancer/dir | egrep Location: Location: http://serverA/dir/ # lynx -mime_header http://loadbalancer/dir | egrep Location: Location: http://serverB/dir/
Accessing http://loadbalancer/dir will result in a redirect to http://serverA/dir/ (if it's serverA's turn) instead of http://loadbalancer/dir/. This happens because serverA simply doesn't know about the load balancer at all.
The solution is to tell the load balancer to rewrite all serverX addresses to the load balancer's address:
ProxyPassReverse / http://serverA/ ProxyPassReverse / http://serverB/ ProxyPassReverse / http://serverC/ ProxyPassReverse / http://serverD/
Now all server generated redirects will get rewritten to the load balancers address:
# lynx -mime_header http://loadbalancer/dir | egrep Location: Location: http://loadbalancer/dir/
Of course in real life the load balancer address would be something like http://www.sun.com.