Skip to content

Instantly share code, notes, and snippets.

@gagarine
Created August 3, 2012 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagarine/3247690 to your computer and use it in GitHub Desktop.
Save gagarine/3247690 to your computer and use it in GitHub Desktop.
drupal nginx and browser language detection
map $http_accept_language $lang {
default de;
~*fr fr;
~*it it;
}
server {
server_name _ site.com;
root /var/www/site.com/drupal;
client_max_body_size 10m;
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)$ {
# allow 193.168.0.0/16;
# 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;
}
location ~ \.php$ {
if ($args = '') {
rewrite ^/index.php$ /$lang redirect;
}
if ($args = 'q='){
rewrite ^/index.php$ /$lang? redirect;
}
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 127.0.0.1:9000;
}
# Fighting with ImageCache? This little gem is amazing.
location ~ ^/sites/.*/files/imagecache/ {
try_files $uri @rewrite;
}
# 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;
}
}
@pgrm
Copy link

pgrm commented Feb 3, 2017

Add * to language matching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment