<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>RealityForge.org: Proxy to Lighttpd for Rails apps</title>
    <link>/articles/2005/11/30/proxy_to_lighttpd</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>A little short for a storm trooper</description>
    <item>
      <title>Proxy to Lighttpd for Rails apps</title>
      <description>&lt;p&gt;Over the last few weeks I have been looking at what is required 
to deploy rails applications in an environment with a peak load 
of about 30 requests a second but with an average rate of 1 request 
per second.&lt;/p&gt;


	&lt;p&gt;I am running Apache and initially I was hesitant to try &lt;a href="http://www.fastcgi.com/"&gt;fastscgi&lt;/a&gt; due to the horror stories that 
I read about on the rails mailing list. I initially tried 
&lt;a href="http://www.modruby.net/en/"&gt;mod_ruby&lt;/a&gt; but it was not speedy and it 
consumed large chunks of memory. I assume this was due to to the ruby
interpreter being added to each process.&lt;/p&gt;


	&lt;p&gt;Next I migrated to fastcgi which was not anywhere near as painful 
as I had heard. I followed the directions in &lt;a href="http://scottstuff.net/blog/articles/2005/07/20/apache-tuning-for-rails-and-fastcgi"&gt;Apache tuning for Rails 
and FastCGI&lt;/a&gt;
and I had it up and running in no time. Very occasionally I am seeing 
fastcgi processes that are left alive after a web server reload. Apparently &lt;a href="http://www.lighttpd.net/"&gt;Lighttpd&lt;/a&gt; does not have this problem but I need
to stick with Apache2 because of applications running on the server.&lt;/p&gt;


	&lt;p&gt;I want to try an approach that I read about on the rails mailing list that involves proxying requests to Lighttpd from Apache2 using configuration like the following. This would then allow me to run a separate Lighttpd on to handle the rail requests.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;lt;VirtualHost *:80&amp;gt;
    ServerName napts.realityforge.org
    ProxyPass / http://napts.realityforge.org:8080/
    ProxyPassReverse / http://napts.realityforge.org:8080/
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;I also noticed an easy way to host multiple rails applications on one hostname. Previously I had created a new hostname for each rails application ala napts.realityforge.org, iplan.realityforge.org, etc.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;lt;VirtualHost *:80&amp;gt;
    ServerName www.realityforge.org
    ProxyPass /napts/ http://www.realityforge.org:8080/
    ProxyPassReverse /napts/ http://www.realityforge.org:8080/
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;And then in my rails application I need to add the following to my environment.rb&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;ActionController&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;AbstractRequest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;relative_url_root&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;/napts&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Pretty neat! and it clears up many of my remaining issues with rails.&lt;/p&gt;</description>
      <pubDate>Wed, 30 Nov 2005 12:12:00 +1100</pubDate>
      <guid isPermaLink="false">urn:uuid:f762de217ee3d7f9b1917c3b07437c5f</guid>
      <author>Peter Donald</author>
      <link>http://www.realityforge.org/articles/2005/11/30/proxy_to_lighttpd</link>
      <category>Rails</category>
      <trackback:ping>http://www.realityforge.org/articles/trackback/7</trackback:ping>
    </item>
  </channel>
</rss>
