2009年4月6日星期一

转: Drupal Boost rules for nginx

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;
}

-------------------------------------------
i3server
i3server
www.86-00.com

没有评论: