Skip to content

Instantly share code, notes, and snippets.

@benhosmer
Last active November 28, 2018 04:42
Show Gist options
  • Save benhosmer/5118626 to your computer and use it in GitHub Desktop.
Save benhosmer/5118626 to your computer and use it in GitHub Desktop.
My Drupal 6/7 nginx site configuration file.
# Drupal 6 NGINX Configuration File
# Enable www.mysite.com or mysite.com to be served
server {
server_name www.mysite.com;
rewrite ^/(.*) $scheme://mysite.com/$1 permanent;
}
server {
server_name mysite.com;
access_log /var/log/nginx/mysite.com-access.log;
error_log /var/log/nginx/mysite.com-error.log;
root /usr/share/nginx/html/mysite.com; ## <-- Your only path reference.
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# This matters if you use drush
location = /backup {
deny all;
}
# Very rarely should these ever be accessed outside of your lan
#location ~* \.(txt|log)$ {
location ~* \.log$ {
allow 127.0.0.1;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
location / {
# This is cool because no php is touched for static content
try_files $uri @rewrite;
}
location @rewrite {
# Some modules enforce no slash (/) at the end of the URL
# Else this rewrite block wouldn't be needed (GlobalRedirect)
rewrite ^/(.*)$ /index.php?q=$1;
}
# This is using spawn-fcgi to process .php files
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php-fcgi.sock;
}
# Fix imagecache locations
location ~* /files/imagecache/ {
access_log off;
try_files $uri @mysite; #imagecache support - now it works
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# Catch image styles for D7 too.
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
location ~* ^.+\.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment