<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>RWVHP - Work</title>
  <id>tag:www.rwvhp.com,2008:mephisto/work</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  <link href="http://www.rwvhp.com/feed/work/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.rwvhp.com/work" rel="alternate" type="text/html"/>
  <updated>2007-12-17T18:52:01Z</updated>
  <entry xml:base="http://www.rwvhp.com/">
    <author>
      <name>shift</name>
    </author>
    <id>tag:www.rwvhp.com,2007-12-17:3</id>
    <published>2007-12-17T12:52:00Z</published>
    <updated>2007-12-17T18:52:01Z</updated>
    <category term="Work"/>
    <link href="http://www.rwvhp.com/work" rel="alternate" type="text/html"/>
    <title>Work</title>
<content type="html">
            &lt;p&gt;I work for &lt;a href=&quot;http://amazing-media.com&quot;&gt;Amazing Media&lt;/a&gt; as a &lt;a href=&quot;http://www.rubyonrails.org&quot;&gt;Rails&lt;/a&gt; Developer.&lt;/p&gt;


	&lt;p&gt;We are currently working on &lt;a href=&quot;http://amazingtunes.com&quot;&gt;amazingtunes.com&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rwvhp.com/">
    <author>
      <name>shift</name>
    </author>
    <id>tag:www.rwvhp.com,2007-03-07:12</id>
    <published>2007-03-07T06:30:00Z</published>
    <updated>2008-01-28T06:41:56Z</updated>
    <category term="Ruby"/>
    <category term="Work"/>
    <category term="apache"/>
    <category term="mongrel"/>
    <category term="rails"/>
    <category term="ruby"/>
    <link href="http://www.rwvhp.com/work/apache-2-2-mongrel" rel="alternate" type="text/html"/>
    <title>Apache 2.2 + Mongrel</title>
<content type="html">
            &lt;p&gt;This isn&#8217;t so much a blog post as somewhere convenient to put some information for ncl.rb.&lt;/p&gt;


	&lt;p&gt;My Apache 2.2 + modproxybalancer virtualhost config&lt;/p&gt;


&lt;pre&gt;
&amp;lt;VirtualHost *:80&amp;gt;
  ServerName yourapp.com
  DocumentRoot /home/web/yourapp.com/current/public/
  &amp;lt;Directory &quot;/home/web/yourapp.com/current/public&quot;&amp;gt;
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  &amp;lt;/Directory&amp;gt;
  # Configure the cluster member proxy
  &amp;lt;Proxy balancer://your_app_cluster&amp;gt;
    BalancerMember http://127.0.0.1:3000
    BalancerMember http://127.0.0.1:3001
    BalancerMember http://127.0.0.1:3002
    BalancerMember http://127.0.0.1:3003
  &amp;lt;/Proxy&amp;gt;
  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 /var/log/apache/app_error.log
  CustomLog /var/log/apache/app_access.log combined
&amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;

	&lt;p&gt;Now if you take the above example it&#8217;ll send all requests to your pack of mongrels, but say you want to have more then one application running on your domain (say beast).&lt;/p&gt;


You&#8217;ll need to create another proxy balancer
&lt;pre&gt;
  &amp;lt;Proxy balancer://your_second_app_cluster&amp;gt;
    BalancerMember http://127.0.0.1:3004
    BalancerMember http://127.0.0.1:3005
    BalancerMember http://127.0.0.1:3006
    BalancerMember http://127.0.0.1:3007
  &amp;lt;/Proxy&amp;gt;
&lt;/pre&gt;
And then add the RewriteRule for it

&lt;pre&gt;
RewriteRule ^/forums/(.*)$ balancer://your_second_app_cluster%{REQUEST_URI} [P,QSA,L]
&lt;/pre&gt;

Now anything going to / that isn&#8217;t /forums/.* will goto yourappcluster and anything with /forums/.* will goto yoursecondapp_cluster
&lt;pre&gt;
&amp;lt;VirtualHost *:80&amp;gt;
  ServerName yourapp.com
  DocumentRoot /home/web/yourapp.com/current/public/
  &amp;lt;Directory &quot;/home/web/yourapp.com/current/public&quot;&amp;gt;
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  &amp;lt;/Directory&amp;gt;
  # Configure the cluster member proxy
  &amp;lt;Proxy balancer://your_app_cluster&amp;gt;
    BalancerMember http://127.0.0.1:3000
    BalancerMember http://127.0.0.1:3001
    BalancerMember http://127.0.0.1:3002
    BalancerMember http://127.0.0.1:3003
  &amp;lt;/Proxy&amp;gt;
  &amp;lt;Proxy balancer://your_second_app_cluster&amp;gt;
    BalancerMember http://127.0.0.1:3004
    BalancerMember http://127.0.0.1:3005
    BalancerMember http://127.0.0.1:3006
    BalancerMember http://127.0.0.1:3007
  &amp;lt;/Proxy&amp;gt;

  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 ^/forums/(.*)$ balancer://your_second_app_cluster%{REQUEST_URI} [P,QSA,L]
  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 /var/log/apache/app_error.log
  CustomLog /var/log/apache/app_access.log combined
&amp;lt;/VirtualHost&amp;gt;
&lt;/pre&gt;
yourappcluster mongrel_cluster.yml
&lt;pre&gt;
---
port: &quot;3000&quot; 
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 4

yoursecondappcluster mongrelcluster.yml

---
port: &quot;3004&quot; 
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 4
&lt;/pre&gt;

	&lt;p&gt;Hope that made sense, as its off the top of the head apart from the base apache 2.2 vhost config&lt;/p&gt;


	&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt; If your running a Rails app under a path remember to set&lt;/p&gt;


&lt;pre&gt;
ActionController::AbstractRequest.relative_url_root = '/path'
&lt;/pre&gt;

	&lt;p&gt;In your environment.rb or your links will be wrong&lt;/p&gt;
          </content>  </entry>
</feed>
