Having one's own lighttpd and running it too
I’ve been trying to think about some flexible but solid ways of “virtual hosting” lighttpd, and considering it’s “lack of an htaccess” I want to provide people with access to the config. While talking to David today, he pointed out two things: -f and conditionals.
Apache’s httpd has-f where you can use it to specify an alternate ServerConfigFile, and it is used the same way in lighttpd. So I thought I try it out on Jamis Buck (with his permission).
First thing was to make some directories in /home/jamis/ and touch some log files
mkdir lighttpd mkdir var mkdir var/run mkdir var/log touch var/log/lighttpd.error.log touch var/log/apache.log
And copied in the main lighttpd.conf
cp /usr/local/etc/lighttpd.conf /home/jamis/lighttpd/lighttpd.conf
Then as a quickie, let’s change some stuff:
server.document-root = "/usr/home/jamis/public_html/jamis" server.errorlog = "/usr/home/jamis/var/log/lighttpd.error.log" server.indexfiles = ( "blog.cgi" ) server.pid-file = "/usr/home/jamis/var/run/lighttpd.pid" accesslog.filename = "/usr/home/jamis/var/log/apache.log" server.port = 8181 server.bind = "jamis.jamisbuck.org" server.username = "jamis" server.groupname = "jamis"
And what he has going there is ruby cgi so
cgi.assign = ( ".rb" => "/usr/local/bin/ruby",
".cgi" => "/usr/local/bin/ruby" )
OK, let start her up
/usr/local/sbin/lighttpd -f /usr/home/jamis/lighttpd/lighttpd.conf
Oh my, that worked and let’s see what it’s memory usage is compared to TextDrive’s Manuals
txd 0.1 %MEM 3.2MB /usr/local/sbin/lighttpd -f /usr/local/etc/lighttpd.confjamis 0.1 %MEM 2.7MB /usr/local/sbin/lighttpd -f /usr/home/jamis/lighttpd/lighttpd.conf
www 1.1% 34.2MB /usr/local/sbin/httpd
Not bad, 2.7MB for his process, and it’s at about 1/10th that of a single httpd child.
How many httpd’s we usually have running?
> ps ax | grep -c httpd 74 > ps ax | grep -c lighttpd 2
Oh.
That’s a difference, especially considering how they behave when they scale.
Let’s take a look at Jamis’s site under lighttpd.
> curl -I http://jamis.jamisbuck.org:8181/blog.cgi HTTP/1.1 200 OK Connection: close Date: Thu, 17 Feb 2005 08:37:44 GMT Content-type: text/html Last-modified: Wed, 16 Feb 2005 11:16:49 GMT Server: lighttpd/1.3.10
Not bad.
And in an environment with Apache, what if I proxy it through a light install of Apache?
Let start with a simple Proxy
ProxyPass /lighttpd1/ http://jamis.jamisbuck.org:8181/blog.cgi/
And we can take a look at this and then the headers show that it’s served by both:
> curl -I http://jamis.jamisbuck.org/lighttpd1/ HTTP/1.1 200 OK Date: Thu, 17 Feb 2005 08:41:49 GMT Server: lighttpd/1.3.10 Content-type: text/html; charset=UTF-8 Last-modified: Wed, 16 Feb 2005 11:16:49 GMT Vary: Accept-Encoding Served-By: TextDrive's Textpache Connection: close
Notice that all links though aren’t correct for it being served from lighttd.
Let’s see what happens when have both ProxyPass and ProxyPassReverse
ProxyPass /lighttpd2/ http://jamis.jamisbuck.org:8181/blog.cgi/ ProxyPassReverse /lighttpd2/ http://jamis.jamisbuck.org:8181/blog.cgi/
The result is relatively similar but feels slower to me.
> curl -I http://jamis.jamisbuck.org/lighttpd2/ HTTP/1.1 200 OK Date: Thu, 17 Feb 2005 08:44:44 GMT Server: lighttpd/1.3.10 Content-type: text/html; charset=UTF-8 Last-modified: Wed, 16 Feb 2005 11:16:49 GMT Vary: Accept-Encoding Served-By: TextDrive's Textpache Connection: close
Again notice that there’s no love on the Category links. So how about we involve another fun module mod_proxy_html which should rewrite the html according to how we configure it
ProxyPass /lighttpd3/ http://jamis.jamisbuck.org:8181/blog.cgi/ ProxyPassReverse /lighttpd3/ http://jamis.jamisbuck.org:8181/blog.cgi/ ProxyHTMLURLMap http://jamis.jamisbuck.org:8181/blog.cgi/ /lighttpd3 <Location /lighttpd3/> SetOutputFilter proxy-html ProxyHTMLURLMap /blog.cgi /lighttpd3 ProxyHTMLURLMap /lighttpd3 /lighttpd3/ RequestHeader unset Accept-Encoding </Location>
Ah ha! Now when I look at http://jamis.jamisbuck.org/lighttpd3/ I see that the category links have been rewritten so that http://jamis.jamisbuck.org/lighttpd3/computers and http://jamis.jamisbuck.org/lighttpd3/programming/languages works fine. There does seem to be some trailing slashes issues on some of the categories (hey, I told you this was a quickie).
And …
> curl -I http://jamis.jamisbuck.org/lighttpd3/programming/languages HTTP/1.1 200 OK Date: Thu, 17 Feb 2005 08:52:33 GMT Server: lighttpd/1.3.10 Content-type: text/html; charset=UTF-8 Last-modified: Wed, 16 Feb 2005 11:16:49 GMT Served-By: TextDrive's Textpache Connection: close Transfer-Encoding: chunked
So the next step is to play around with conditionals as an easy means for Jamis to “virtual host up” his stuff, with a config that would start with something like
$HTTP["host"] =~ "jamis\.jamisbuck\.org$" {
server.document-root = "/usr/home/jamis/public_html/jamis/"
server.indexfiles = ( "blog.cgi")
}
And then also introduce conditionals that contain ruby-fcgi spawns.
And when it’s time to try out the proxying, have to remember to turn ProxyPreserveHost On because I imagine that it’s a good idea to pass the Host: line to a lighttpd that would be using it to virtual host.
·:· Posted 17 February 2005, 07:57 by Jason Hoffman to Lighttpd |

Good job Jason!
Q: Is this a possibility for what you’re considering as a new Virtual Private Server environment?
— Cameron 17 February 2005, 19:42 #
— Jason Hoffman 19 February 2005, 06:54 #
— Dean Allen 23 February 2005, 08:04 #
— Dean Allen 23 February 2005, 08:05 #
— Dean Allen 23 February 2005, 08:14 #
— Scott Cropper 26 February 2005, 23:08 #