Drupal Nginx configuration
Drupal 6
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=someservername.com:10m inactive=20m max_size=500m;
server {
listen 80;
server_name someservername.com;
root /srv/http/someservername.com/drupal;
access_log /var/log/nginx/someservername.com.access.log;
error_log /var/log/nginx/someservername.com.error.log warn;
log_subrequest on;
client_max_body_size 8M;
client_body_buffer_size 128k;
index index.php index.html;
if ($http_user_agent ~ ^SiteSucker|^iGetter|^larbin|^LeechGet|^RealDownload|^Teleport|^Webwhacker|^WebDevil|^Webzip|^Attache|^SiteSnagger|^WX_mail|^EmailCollector|^WhoWhere|^Roverbot|^ActiveAgent|^EmailSiphon|^CrownPeak-HttpAgent|^$) {
rewrite .* /404.html break;
}
error_page 404 @drupal;
location /install.php {
allow mgmthost_ip;
deny all;
include fastcgi_params.php;
}
location / {
try_files $uri $uri/ @drupal;
}
# hide protected files
location ~* \.(aspx?|cgi|dll|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$ {
deny all;
}
# forbid running php in upload dir
location ~ ^/sites/[^/]+/files/.*\.php {
deny all;
}
location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|swf|mp4|flv)$ {
access_log off;
expires 30d;
}
# pass the PHP scripts to FastCGI server listening on unix socket
location ~ .*\.php$ {
include fastcgi_params.php;
try_files $uri @drupal;
fastcgi_cache someservername.com;
fastcgi_cache_key $scheme$host$request_uri;
fastcgi_cache_valid 200 301 302 304 1h;
fastcgi_pass_header Set-Cookie;
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_cache_bypass $cookie_DRXrtArgs; # logged in user
fastcgi_no_cache $cookie_DRXrtArgs;
}
location @drupal {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
open_file_cache max=1000 inactive=20s;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
This config has caching enabled but in a greedy mode. Only use these cache settings if you need to serve high volume traffic, else it's better to use
$http_cookie instead of
$cookie_DRXrtArgs.
--
AvishaiIshShalom - 28 Aug 2010