Project

General

Profile

Actions

MigratingFromApache » History » Revision 16

« Previous | Revision 16/51 (diff) | Next »
jan, 2005-07-28 16:32


= Migrating from Apache to lighty =

Basic Options

{{{
Options +FollowSymLinks
}}}

becomes

{{{
server.follow-symlinks = "enable"
}}}

Accesslog

Accesslogs are written by mod_accesslog and support the same options in

{{{
accesslog.format = ...
}}}

as Apache.

If you need logfile rotation use one of two way:

=== logrotate ===

If you don't use the debian package copy ./debian/lighttpd.logrotate to /etc/logrotate.d/

logrotate will send lighttpd a SIGHUP when it is time to rotate the logs and lighttpd reopen the logs accordingly.

=== cronolog ===

With cronolog you pipe the accesslog to a pipe and let a external program handle the logfile writing:

{{{
accesslog.filename = "|/usr/sbin/cronolog /web/logs/%Y/%m/%d/access.log"
}}}

mod_rewrite

[http://www.lighttpd.net/documentation/rewrite.html mod_rewrite] is more trickier as the idea how it is handled is completly different.

First of all we always match on the full relative request-uri that is submitted by the user. That means that we are always using the [QSA] (query string append) flag from [http://httpd.apache.org/docs/mod/mod_rewrite.html mod_rewrite in Apache].

This is example is based on a problem from http://dir.onlinesearch.ws/ sent in by dbird@freenode.

{{{
RewriteEngine On
RewriteBase /instadir/
RewriteCond %{REQUEST_FILENAME} -d
  1. Fix trailing slash problem
    RewriteRule (.+[/])$ $1/ [R,L]
  2. Do not try to treat the following resources as parameters to index.php
    RewriteRule ^index.php.*$ - [L]
    RewriteRule ^dmoz.css$ - [L]
    RewriteRule ^admin[/]?.*$ - [L]
    RewriteRule ^img[/]?.*$ - [L]
    RewriteRule ^[/]{0,}(.*)$ index.php?area=browse&cat=$1 [QSA,L]
    }}}

These rewrites want to rewrite everything that is not the index.php, dmoz.css, admin-interface or something from the image-directory to a parameter of the index.php page. The base directory for this match is ''/instadir/''.

{{{
  1. for all URLs in /instadir/ that are not index.php, dmoz.css, admin or img, do ...
    $HTTP["url"] =~ "^/instadir/(?!index.php|dmoz.css|admin|img)" { ## don't get afraid by the pattern, it matches the request-string ## and the optional query-string
    url.rewrite = ( "^/instadir/([^?]*)(?:\?(.*))?" =>
    "/instadir/index.php?area=browse&cat=$1&$2" )
    }
    }}}

The conditional is using regex-magic called [http://perlpod.com/5.9.1/pod/perlre.html#Extended%20Patterns zero-width negative look-ahead assertion] and is something from the advanced chapters of your [http://www.oreilly.com/catalog/regex/ regex book].

mod_fastcgi

If you have 2 extensions assigned to on fastcgi handler in Apache like

{{{
AddType fastcgi-php .php .phtml
}}}

you need two entries in the fastcgi.server config:

{{{
fastcgi.server = ( ".php" => (( "bin-path" => "/my/fastcgi-php",
"socket" => "/path/to/php.socket" )),
".phtml" => (( "socket" => "/path/to/php.socket-0" ))
)
}}}

The first entry will create the php-fcgi process and the second will reuse the same socket.

If you need want to use PHP and Python in the same setup, just add two extensions:

{{{
fastcgi.server = ( ".php" => (( "bin-path" => "/my/fastcgi-php",
"socket" => "/path/to/php.socket" )),
".py" => (( "host" => "127.0.0.1", port = 3200 ))
)
}}}

For this setup python was spawned externally and is a waiting for requests at port 3200, localhost.

Updated by jan over 19 years ago · 16 revisions