Drupal has a nice module to boost its performance called Boost. It provides static page caching for anonymous users, i.e. it creates a static page for each url once it was requested. Static caching fully relies on rewrite rules, and Boost developers provide sample mod_rewrite rules to use with apache web server.
Unfortunately I couldn't find any working rules for nginx, so I have to develop them by myself. The main problem with nginx is that you can't specify multiple conditions. However there is a workaround (an ugly one, but it works).
Following lines should be inserted under "location /". Remember that order is important here, last rule is default drupal rule for nginx.
## Boost rewrite rules
set $boost "";
if ( $request_method = GET ) {
set $boost G;
}
if ($http_cookie !~ "DRUPAL_UID") {
set $boost "${boost}D";
}
if ($query_string = "") {
set $boost "${boost}Q";
}
if ( -f $document_root/cache/$host/0/index.html ) {
set $boost "${boost}I";
}
## GDQI, request is for main page
if ($boost = GDQI) {
rewrite ^/$ /cache/$server_name/0/index.html break;
}
if ( -f $document_root/cache/$host/0$request_uri.html ) {
set $boost "${boost}F";
}
## GDQIF, the request is for subpage
if ($boost = GDQIF) {
rewrite .? /cache/$server_name/0$request_uri.html break;
}
if ( -d $document_root/cache/$host/0$request_uri ) {
set $boost "${boost}E";
}
if ( -f $document_root/cache/$host/0$request_uri/index.html ) {
set $boost "${boost}F";
}
## GDQEF, the request is for module main page
if ($boost = GDQEF) {
rewrite .? /cache/$server_name/0$request_uri/index.html break;
}
## Boost rewrite rules end
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
Tuesday, February 10, 2009
Subscribe to:
Post Comments (Atom)
4 comments:
mungrThanks for this!!!
I'm using it with vbdrupal and had an issue where it would think I was logged out, all I did was change the 'DRUPAL_UID' to 'bbuserid' and it's rolling along!
Man!!
In one word?
THANKS!!! :D
what will the boost rewrite rule be if drupal is installed in abc.com/subdir/ ?
Boost rules can be found on the nginx drupal user group http://groups.drupal.org/nginx
Post a Comment