After a bit back and forth with configuring Drupal and nginx to work together, I've come up with the below configuration for a site. It works well, both with private and public file systems. However, as I am fairly new to nginx I'd like to hear if there is something with this configuration that I should change (for
Please note! I'm aiming towards getting feedback on a general purpose Drupal configuration. That is, a configuration which others who are trying out Drupal + nginx can "copy paste" to get up and running.
Update 1: I've (hopefully) improved the configuration file slightly, and I've added descriptive comments to explain what the various parts of the file are doing. I've also, according to input, enabled the 'open_file_cache' directive.
/etc/nginx/nginx.conf (partly)
# Cache information about local files.
open_file_cache max=1000 inactive=3600s;
open_file_cache_errors on;
open_file_cache_min_uses 3;
open_file_cache_valid 1800s;
/etc/nginx/sites-available/example.conf
server {
listen 80;
server_name ~^(www\.)?((example|example-web).+)$;
access_log /home/example/www/logs/access.log;
error_log /home/example/www/logs/error.log;
root /home/example/www/public_html;
# Do not log events related to 'favicon.ico'.
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Do not log events related to 'robots.txt'.
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Do not allow access to certain file types from outside the
# network, regardless of their location in the file system.
location ~* \.(txt|log|htaccess|htpassword)$ {
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
}
# Requests are by default rewritten as defined in the @rewrite
# location
location / {
try_files $uri @rewrite;
}
# The path '/system/files' is a virtual path managed by Drupal,
# and thus needs to be handled by Drupal. Logging is disabled
# for these requests, and server response is set to expire
# after 7 days.
location ~* /system/files/ {
try_files $uri @rewrite;
expires 7d;
access_log off;
}
# Images and static content, which is defined as specific file
# types, will be served directly by Nginx. These requests will
# not be logged, and is set to expire after 30 days.
location ~* \.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
}
# All requests are handled by index.php, and we need to make
# sure that this still happens even if the site runs with clean
# urls enabled.
location @rewrite {
rewrite_log on;
rewrite ^/(.*)$ /index.php?q=$1;
}
# Delegate handling of '.php' files to PHP.
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/example.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}