This is a better Drupal nginx config. Built from a combination of contributions from here:

https://groups.drupal.org/node/305633
https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/
This commit is contained in:
Tim Bracken 2016-08-16 16:32:59 -04:00
parent 95ef5e1e70
commit 928451ae88

View File

@ -1,28 +1,56 @@
server {
listen 80;
listen 80;
listen [::]:80;
server_name site_a.dev;
root /var/www/site_a;
index index.php;
#domain name
server_name drupal8.dev;
#file document root. This has to match one of the volumes in docer-composer.yml
root /var/www/drupal8;
# This is the full path to your index file
index index.php index.html index.htm;
## serve imagecache files directly or redirect to drupal if they do not exist.
location ~* files/styles {
access_log off;
expires 30d;
try_files $uri @drupal;
}
## serve imagecache files directly or redirect to drupal if they do not exist.
location ~* ^.+.(xsl|xml)$ {
access_log off;
expires 1d;
try_files $uri @drupal;
}
## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
index index.php;
# This is cool because no php is touched for static content
try_files $uri $uri/ @rewrite;
expires max;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/site_a;
location @drupal {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
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$ {
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;