Posted by Vince Wadhwani on Oct 18, 2006

Please see Part I here

So a few weeks ago I had a problem where code I was running worked in webrick but not lighttpd. Turns out there was a simple print statement that was causing that. Drove me nuts trying to solve it.

Well, this morning I had *another* instance where code worked in webrick but not lighttpd. This time firebug was no help at all:

Here is a comparison of the output from Firebug

WORKS (webrick)
Cache-Control: no-cache
Connection: close
Date: Wed, 18 Oct 2006 13:49:31 GMT
Content-Type: text/javascript; charset=UTF-8
Server: WEBrick/1.3.1 (Ruby/1.8.4/2005-12-24)
Content-Length: 165
Set-Cookie: _session_id=05f05d72373a31ff76cbf0645d419618; path=/

DOES NOT WORK (lighttpd)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/javascript
Set-Cookie: _session_id=36fa39df475fe2c6f2ddc5128076e478; path=/
Cache-Control: no-cache
Date: Wed, 18 Oct 2006 14:01:18 GMT
Server: lighttpd

Pretty similar, eh? Well, it turns out the problem was once again in my ruby code. This time, it was because I was capturing the IP address of the visitor (to prevent duplicate counting of votes) using this method:

<%= @ip = request.remote_host %>

You guessed it, that does not work using lighttpd! The solution was to use this code instead which did the trick:

<%= @ip = request.env["REMOTE_ADDR"] %>

With that in place, my code works again and lighttpd keeps flying light and straight.

Special thanks to runa on #lighttpd IRC for giving me some pointers.
And thanks to moo-light for helping me render the above code in typo.

Feb 10, 2008 Update: See this post if the above snippet stopped working for you.