tagged lighttpd
I've been working with lighttpd's mod_magnet recently to provide Routing & Controller logic to static web sites where PHP is a bit heavy handed (and Rails even more so.)
This Lua bit lets you happily leave those ugly file extensions off URL's:
- clean, simple URL's make the web human-friendly
- actual filename extensions (and application platform) can losslessly change over time
- script runs as a Lua bytecode machine in lighttpd core; it's fast
Save the following as extensionless_urls.lua next to your lighttpd.conf:
if (not lighty.stat(lighty.env["physical.path"])) then
file_extensions = { ".html", ".php" }
for key, file_extension in pairs(file_extensions) do
if (lighty.stat(lighty.env["physical.path"] .. file_extension)) then
lighty.env["uri.path"] = lighty.env["uri.path"] .. file_extension
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["physical.path"] =
lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
break
end
end
end
Note the file_extensions array, which should be composed of the extensions to search for by priority. As shown above, an ".html" file will be found before a ".php" file by the same name. Keep this array short: one entry, if all your files have the same extension.
Adjust lighttpd.conf
# Include the mod_magnet early in the module list.
server.modules = ( "mod_magnet" )
# Call the Lua machine for each physical file request.
# Change this path to match the location of your script.
magnet.attract-physical-path-to = (
"/etc/lighttpd/extensionless_urls.lua" )
Restart lighttpd, and you now have stat-cached, fuzzy URL matching!
To get up-and-running with lighttpd+Lua, see:
mod_magnet on OS X
Yesterday I filed Lighttpd bug #217 explaining the critical failure I have been experiencing on OpenBSD/Lighttpd wherein HTTPS would fail to transfer more than first 16KB of data.
Within 10-minutes of submitting the bug, a second person confirmed the bug on OpenBSD.
12-hours later, the bug was fixed and already rolled into this morning's Lighttpd 1.4.1 release.
The SSL bug is that Lighttpd was relying on typical memory mapping behavior which has been randomized in OpenBSD to avoid low-level bugs that would traditionally go undetected.
OpenBSD's proactive security practices are boldly moving forward with the pending release of OpenBSD 3.8.
The OpenBSD project is bringing to light the low-level bugs in UNIX software. These "silent bugs", which may lurk with hidden vulnerabilities for years, can be found and removed through contributions within the open-source community.
This is open-source at it's finest! Cheers to Jan & the Lighttpd developers for a sweet web server and to the OpenBSD crew for doing it right!
Updated: Tuesday, 23rd August 2005 with OpenBSD project information.
This site (and several others that are served on this host) are all running under Lighttpd. That's right, no more Apache web server coming 'round here!
Weeks of odd-hour planning, compiling & configuring are complete.
Normal human prose on more loving and fleshy topics will soon follow!
*Mars
Update: Saturday, 20th August 2005 I have been unable to make these rewrite rules work fully. Experimentation has lead to variations that fix one rewrite problem at the expense of breaking a different facet of the URL schema. Gallery's mixing of query strings with rewritten URL's seems to be the core issue. So, let me know if you happen to solve the problem completely!
Update: Monday, 22nd August 2005 I've simply disabled URL rewriting in Gallery's config.php file to permit Gallery to function under Lighttpd:
$gallery->app->feature["rewrite"] = 0;
Update: Monday, 2nd January 2006 From David Lutz:
I decided to continue banging my head on the rewrite wall for a little longer and came up with a set of rules that do an excellent job for me. If you are interested in giving them a try or posting them on your site here they are:
# URL Rewrite
url.rewrite = (
# Gallery v1: Pass any request for something in selected sub-dirs
"^/gallery/(css|docs|images|java|js|setup|skins|tools)/(.*)$" => "/gallery/$1/$2",
# Gallery v1: Pass any request for a .php file in the main gallery dir
"^/gallery/([^.\?/]+.php(?:\?.*)?)" => "/gallery/$1",
# Gallery v1: Rewrite album/index w/optional args
"^/gallery/([^.\?/]+)/([0-9]+)(?:\?(.*))?" => "/gallery/view_photo.php?set_albumName=$1&index=$2&$3",
# Gallery v1: Rewrite album/id w/optional args
"^/gallery/([^.\?/]+)/([A-Za-z_0-9\-]+)(?:\?(.*))?" => "/gallery/view_photo.php?set_albumName=$1&id=$2&$3",
# Gallery v1: Rewrite album w/optional args
"^/gallery/([^.\?/]+)(?:\?(.*))?" => "/gallery/view_album.php?set_albumName=$1&$2",
)
To get Gallery running under the Lighttpd/PHP-FastCGI web server is no problem, except you'll soon find that the Apache RewriteRules to make pretty URL's don't work!
I figured it out, and so here's the answer.
Read the rest of this entry