<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CocoaDust &#187; Web Development</title>
	<atom:link href="http://cocoadust.com/tags/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://cocoadust.com</link>
	<description>Cocoa, Macs, Web, User Experience and more…</description>
	<lastBuildDate>Sat, 24 Nov 2007 15:49:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Apache 1.3, Rails &amp; lighttpd</title>
		<link>http://cocoadust.com/2007/03/27/apache-13-rails-lighttpd/</link>
		<comments>http://cocoadust.com/2007/03/27/apache-13-rails-lighttpd/#comments</comments>
		<pubDate>Tue, 27 Mar 2007 20:08:50 +0000</pubDate>
		<dc:creator>Steve Harris</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://cocoadust.com/2007/03/27/apache-13-rails-lighttpd/</guid>
		<description><![CDATA[Apart from the WordPress blog, the dynamic parts of my Reinvented Software site is all Ruby on Rails. The pages there could be better (i.e. sexier), but I ran out of self-imposed time. I spent a few weeks last year rewriting those pages and what used to be an entire J2EE backend in Rails and [...]]]></description>
			<content:encoded><![CDATA[<p>Apart from the WordPress blog, the dynamic parts of my <a href="http://reinventedsoftware.com/">Reinvented Software</a> site is all Ruby on Rails. The pages there could be better (i.e. sexier), but I ran out of self-imposed time. I spent a few weeks last year rewriting those pages and what used to be an entire J2EE backend in Rails and felt cleansed as a result. </p>
<p>(Yes, I know J2EE was complete overkill &#8211; it would be for running the Universe &#8211; but when I set up the business, I wanted to keep my hand in just in case things didn&#8217;t work out and I&#8217;d end up back in corporate hell. Thankfully, that didn&#8217;t happen.)</p>
<p>My biggest concern was how to serve the files. My server is running Apache 1.3.x, I could have upgraded to Apache 2.0 but that would been a lot of work. I also heard Apache 2 working with FastCGI could be quite heavy on resources and that was off-putting. I could have moved entirely to lighttpd, but that was too scary, so I decided it would be better to serve the Rails stuff with lighttpd and have Apache do the rest. </p>
<p>I <a href="http://steveh.wordpress.com/2006/06/01/and-about-time-too/">wrote about this on my personal blog</a> at the time (boring my non-geek friends in the process). From the original post:</p>
<blockquote><p>Apache proxies requests to Lighttpd to serve the Rails stuff (so, for example, you see <tt>http://reinventedsoftware.com/store/</tt> instead of <tt>http://reinventedsoftware.com:3000/store/</tt>), it all works seamlessly.</p>
<p>While I could find instructions out there on how to get Apache proxy to Lighttpd to serve an entire Rails application from a specific URL (e.g. <tt>http://reinventedsoftware.com/myrailsapp/</tt>) this mixing and matching wasn&#8217;t documented &#8211; so I will probably put something about this on the Rails Wiki. It was quite straightforward once I had worked it all out.</p></blockquote>
<p><a href="http://zachhale.com/">Zach Hale</a> came across the post and asked how to set up Apache to work alongside lighttpd, so here is how I did it. Note these instructions are for Apache 1.3.x, I don&#8217;t know how it would work with Apache 2:</p>
<h3>Apache Setup</h3>
<p>In Apache&#8217;s httpd.conf, ensure mod_proxy is loaded:</p>
<pre>LoadModule proxy_module       libexec/libproxy.so</pre>
<p>Then use the ProxyPass and ProxyPassReverse directives to lighttpd for certain paths (note the standard Rails stylesheets and javascripts directories also):</p>
<pre>ProxyPass /news http://localhost:3000/news
ProxyPassReverse /news http://localhost:3000/news

ProxyPass /support http://localhost:3000/support
ProxyPassReverse /support http://localhost:3000/support

ProxyPass /stylesheets http://localhost:3000/stylesheets
ProxyPassReverse /stylesheets http://localhost:3000/stylesheets

ProxyPass /javascripts http://localhost:3000/javascripts
ProxyPassReverse /javascripts http://localhost:3000/javascripts</pre>
<h3>Lighttpd</h3>
<p>In lighttpd.conf ensure server.modules includes mod_alias and mod_proxy:</p>
<pre>server.modules           = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi",
                             "mod_compress", "mod_expire", "mod_alias", "mod_proxy" )</pre>
<p>And further down, add this to handle the aliasing:</p>
<pre>
$HTTP["url"] =~ "^/" {
  server.document-root = CWD + "/public/"
  alias.url = ( "/" => CWD + "/public/" )
  accesslog.filename = CWD + "/log/access.log"
  server.error-handler-404 = "dispatch.fcgi"
  server.errorlog          = CWD + "/log/lighttpd.error.log"
  server.indexfiles = ( "index.html" , "dispatch.fcgi" )
  # rails stuff
  fastcgi.server = ( ".fcgi" =>
    (
        (
       "socket" => CWD + "/log/code.socket",
       "min-procs" => 2,
       "max-procs" => 2,
       "bin-path" =>  CWD + "/public/dispatch.fcgi",
       "bin-environment" => ( "RAILS_ENV" => "production" )
  )))
}
</pre>
<p>I barely understand this stuff, so don&#8217;t ask me to explain it.</p>
<p>Finally, I created symlinks to all the root level folders in the Apache served public_html directory, so that lighttpd could find the files when the user navigates. Here&#8217;s a cut down <tt>ls -l</tt>:</p>
<pre>
dispatch.rb
dispatch.fcgi
dispatch.cgi
stylesheets
javascripts
support -> ../../../public_html/support/
news -> ../../../public_html/news
feeder -> ../../../public_html/feeder
kit -> ../../../public_html/kit
about -> ../../../public_html/about
blog -> ../../../public_html/blog
404.html
500.html</pre>
<p>So, it&#8217;s a bit of a hybrid system. Apache is in control and serves most files, but lighttpd takes care of all the Rails stuff. It&#8217;s been running for 10 months now through some very heavy moments and works really well.</p>
]]></content:encoded>
			<wfw:commentRss>http://cocoadust.com/2007/03/27/apache-13-rails-lighttpd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
