Recipe for wildcard dns entry -> apache [handling static content & location pass-through] -> balancer proxy [ passing to mongrel backend]

26 06 2007

I didn’t find anything QUITE like this, so maybe someone will find this helpful. This is one of those situations where you know apache can do it, it’s just a matter of finding the right combination of tools.
This was wrapped in a virtualhost, with wildcard DNS entries pointing to it, for which you have to use IP-based virtual hosting.

Keep in mind, to have this work (and your apache to parse the conf file) you have load mod_proxy, proxy_balancer_module, proxy_connect_module, and proxy_http_module. Since we are using rewrite, mod_rewrite : )

The FreeBSD ports version of apache 2.2.x compiles all those modules as DSO’s, so you have to be sure find them all in the httpd.conf file.

Two (I believe different) authors have bits incorporated here, thanks to those authors. The file based “site maintenance” rule and the snippet for testing if there is a static file to serve.

This was my first serious encounter with mod_rewrite, so perhaps there are some inefficiencies here.

#Not doing forward proxying
ProxyRequests Off

#need this for my rulez
RewriteEngine on

#logging, rewrite is complex
RewriteLog “/data/www/vhosts/mysitenameorwhatever.com/logs/rewrite.log”
RewriteLogLevel 1

<Proxy * >
Order deny,allow
Allow from all
</Proxy >

#don’t proxy
#this is part that got me a bit messed up
#this is why i have the PT option later (pass through)
<Location /balancer-manager>

SetHandler balancer-manager

Order Deny,Allow
Deny from all
Allow from xxx.81.145.xxx
Allow from xxx.70.19.xxx
</Location>

#to skip processing on valid locations etc
RewriteCond %{REQUEST_URI} ^/balancer-manager
RewriteRule .* %{REQUEST_URI} [QSA,PT]

# Check for maintenance file. Let apache load it if it exists
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteRule . /system/maintenance.html [L]

# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]

# Let apache serve static files (send everything via mod_proxy that
# is *no* static file (!-f)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule .* balancer://my_cluster%{REQUEST_URI} [L,P,QSA]

<Proxy balancer://my_cluster>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>



Actions

Information

Leave a comment