Apache2.2 vhost template for mongrel clusters

Posted by ezmobius Mon, 12 Jun 2006 06:45:00 GMT

Just wanted to share a template vhost for use with apache2.2/mod_proxy_balancer → mongrel_cluster. This vhost takes care of making apache serve all static and page cached requests while forwarding all dynamic requests to the mongrel_cluster.

Thanks to Bradley Taylor author of mongrel_cluster and owner of RailsMachine.com for this config.

<VirtualHost *:80>
  ServerName yourdomain.com
  DocumentRoot /var/rails/your_app/current/public
  <Directory "/var/rails/your_app/current/public">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
  # Configure the cluster member proxy
  <Proxy balancer://your_app_cluster>
    BalancerMember http://127.0.0.1:5000
    BalancerMember http://127.0.0.1:5001
    BalancerMember http://127.0.0.1:5002
  </Proxy>
  RewriteEngine On
  # If there is a maintenence.html file in your
  # public dir all requests will get rerouted to
  # this file.  This is for use with capistrano
  RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /maintenance.html [L]
  # Rewrite index to check for static index.html
  RewriteRule ^/$ /index.html [QSA] 
  # Rewrite to check for Rails cached pages with .html extentions
  RewriteRule ^([^.]+)$ $1.html [QSA]
  # All dynamic requests get sent to the cluster
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://your_app_cluster%{REQUEST_URI} [P,QSA,L]
  # Deflate for clients that support it.
  AddOutputFilterByType DEFLATE text/html text/plain text/xml
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  # Error and access logs.
  ErrorLog logs/your_app_error_log
  CustomLog logs/your_access_log combined
</VirtualHost>

Tags , ,  | 4 comments

Comments

  1. Zed A. Shaw said about 9 hours later:
    Didn't Bradley Taylor write this configuration?
  2. Ezra said about 9 hours later:
    You know you are probably right. I had it lying around and was asked about it enough I posted it here. I'll add attribution for Bradley.
  3. matt clark said 8 days later:
    I ran across an interesting problem with the way Apache passes along header variables to Mongrel (or more correctly, does not). if you use DHH's ssl_requirement plugin, it will be broken under stock Apache 2.2. Here is a link to a hackish fix, but it gets the job done - http://duncandavidson.com/essay/2006/01/railsReverseProxyWithSsl Anyone have a more elegant solution to teaching Apache to share its header info?
  4. Ezra Zygmuntowicz said 17 days later:
    You can get around this by adding the following line to your ssl apache conf file:

    RequestHeader set X-Forwarded-Proto "https"
    

(leave url/email »)

   Preview comment