Archive

Posts Tagged ‘.htaccess’

Converting to lighttpd and dealing with .htaccess

May 8th, 2009 Andrew Rankin No comments

I recently switched this server to Lighttpd (using PHP through FastCGI) from Apache. It was easy enough and I ended up with much faster serving websites, unfortunately I hit a snag on one of my sites that extensively uses .htaccess file for rewrites – which Lighttpd does not support. I didn’t want to bail on the whole switch because of a single site, so looked and came up with a simple solution – proxy to Apache through Lighttpd for items on that site (www.350z.ws). In lighttpds config, this was very easy to accomplish:

# Proxy 350z.ws back to apache
$HTTP["host"] =~ "www.3(5|7)0z.ws" {
        $HTTP["url"] !~ "(wp-content|wp-includes|css|js|php$|^/blog/$)" {
                proxy.server = ( "/" =>
                        ( "localhost" =>
                                ( "host" => "127.0.0.1", "port" => 81 )
                        )
                )
        }
}

Note one (obvious) draw back is that you have to run Apache as well, but since I’m stopping most hits at Lighttpd by serving everything in wp-content, wp-includes, anything with css, js or php in the name, I can greatly reduce the number of Apaches I start and maintain. In my case my Apache prefork config looks like this:

<IfModule mpm_prefork_module>
    StartServers          3
    MinSpareServers       2
    MaxSpareServers       5
    MaxClients          15
    MaxRequestsPerChild   10
</IfModule>

You’ll also notice I’m not proxying the folder where WordPress lives back either, this is because it contains no rewrites for it specifically and will get the majority of the hits.

Categories: Apache, Lighty Tags: , , ,