Posts Tagged ‘Lighttpd’

Apache 2.2 proxy and LightTPD

Monday, August 17th, 2009

The server has just undergone some modifications – previously I was using Lighttpd to serve all of the content, I liked the traffic shaping features and low memory footprint that it had. But I also sorely missed the mod_rewrite functionality and mod_php that was provided by Apache.

The solution was simple. Apache 2.2.13 to serve the Dynamic PHP files and Lighttpd to serve the static files via the Apache Proxy plugin. This results in gaining all the features of Apache but only when I need them; using Lighttpd to serve static content.

The basic setup is simple. Lighttpd runs on port 81, 127.0.0.1 and Apache runs on port 80 of idontplaydarts.com, both point to the same root directory and when Apache sees a request for a file located in either wp-content or wp-includes it instructs lighttpd to handle it. My config file looks something like this.

ProxyPass /wp-content http://127.0.0.1:81/wp-content
ProxyPassReverse /wp-content http://127.0.0.1:81/wp-content

ProxyPass /wp-includes http://127.0.0.1:81/wp-includes
ProxyPassReverse /wp-includes http://127.0.0.1:81/wp-includes

The only issue at the moment is that the latest version of Apache doesn’t yet support the ProxyPassMatch directive. This would let me specify a regular expression such as *.txt to tell Apache to pass all the requests for text files to Lighttpd.

ProxyPassMatch ^(/.*\.txt)$ http://idontplaydarts.com/$1

PassProxyMatch is due to be introduced in Apache 2.2.5, we’re only Apache 2.1.3 at the moment so there is going to be a bit of a wait before I can change my configuration files and allow support for regular expressions with PassProxy.

Its worth mentioning that you can do the proxy the other way round, lighttpd front passing it to Apache but there is not much benefit and you dont get to take advantage of the nice Apache rewrite rules

Reduce load times, speed up your website, increase revenue

Sunday, June 14th, 2009

Page load speed is everything. Tests done by Amazon have shown that an increase in page loading times by 100ms can reduce sales by 1%; when Google added 500ms to its response times traffic dropped 20%. The premise is simple: a faster website means faster feedback to the user which enables a faster user learning curve.

If like me you have a website that is powered by the LLMP (Linux Lighttpd MySQL PHP) stack then there are some simple steps you can take to decrease your page load times. If your running Apache and not Lighttpd then maybe its time to move :) (more…)

Traffic shaping using lighttpd

Wednesday, May 27th, 2009

Now that the server is using lighttpd its become possible to implement traffic shaping, you can even do it per directory which is a nice touch.

$HTTP["url"] =~ “^/photos/” {
connection.kbytes-per-second = 128
}

This limits all urls that start with /photos/ to 128k per second. You can try it on a photo of Queensland Australia that I’ve just uploaded. If you look at the output from wget we can see it in action:

Resolving www.idontplaydarts.com… 80.68.93.53
Connecting to www.idontplaydarts.com|80.68.93.53|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 13858463 (13M) [image/jpeg]
Saving to: `queensland.jpeg’

100%[=============================>] 13,858,463   136K/s   in 1m 46s

2009-05-27 15:44:02 (128 KB/s) – `queensland.jpeg’ saved [13858463/13858463]

And there we have it. Traffic shaping using lighttpd. There are some pitfalls – users can still open multiple connections to your URL using tools such as axel – instructions on installing and using axel on debian can be found on nixCraft

As you can see if we open 4 connections we get 4 times the throughput.

# axel -a -n 4 http://www.idontplaydarts.com/photos/panorama/queensland.jpeg
Initializing download: http://www.idontplaydarts.com/photos/panorama/queensland.jpeg
File size: 13858463 bytes
Opening output file queensland.jpeg.0
Starting download

Connection 3 finished                                                          ]
Connection 2 finished                                                          ]
Connection 0 finished                                                          ]
Connection 1 finished                                                          ]
[100%] [..................................................] [ 524.8KB/s] [00:00]

Downloaded 13.2 megabytes in 25 seconds. (524.79 KB/s)

Lighttpd version 1.5 is going to support a max connections per ip which would be handy if you wanted to prevent people opening multiple connections. Not really that handy for a website but possibly if your serving lots of large static files.

Moving hosts

Sunday, May 17th, 2009

Today I switched hosts and purchased a virtual server from bytemark. I’ve got to say I really like it. It’s cheap, fast and seems to be quite stable. The new setup is

  • PHP 5.3
  • Mysql 5.1
  • Lighttpd

Which I guess makes it a LLMP stack rather than a LAMP stack. I’ve become a big fan of Lighttpd recently, its pretty much Apache but without the bloat. Its also got some nice traffic shaping features that seem to be lacking from Apache and uses way less resources. Pretty handy when your server only has 256mb of ram.

Moving over to a virtual host has been pretty simple as has migrating the blog from blogspot to wordpress. The new virtual host has given me much greater control over my blog so you can expect to see some new funky code in the near future.

Fast php-cgi binary missing?

Tuesday, March 24th, 2009

I was trying to re-compile PHP today to install lighttpd. It needs the fast-cgi option when compiling because unlike Apache it doesn’t use mod_perl. I kept specifying the –enable-fastcgi option but every time I compiled it didn’t make the php-cgi binary. It just made the cli version and that was it.

The problem: apxs the tool that php uses to configure itself with Apache (i wanted PHP setup with both apache and lighttpd) seems to disable the –enable-fastcgi option. This only seemed to happen with Apache 2.2.

The solution: disable the apxs option when you compile and manualy add the config lines to apache if you need it.