Skip to content

Commit 928451a

Browse files
committed
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/
1 parent 95ef5e1 commit 928451a

1 file changed

Lines changed: 42 additions & 14 deletions

File tree

nginx/sites/framework-examples/drupal_8.conf

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,56 @@
11
server {
2-
listen 80;
2+
listen 80;
33
listen [::]:80;
44

5-
server_name site_a.dev;
6-
root /var/www/site_a;
7-
index index.php;
5+
#domain name
6+
server_name drupal8.dev;
87

8+
#file document root. This has to match one of the volumes in docer-composer.yml
9+
root /var/www/drupal8;
10+
11+
# This is the full path to your index file
12+
index index.php index.html index.htm;
13+
14+
15+
## serve imagecache files directly or redirect to drupal if they do not exist.
16+
location ~* files/styles {
17+
access_log off;
18+
expires 30d;
19+
try_files $uri @drupal;
20+
}
21+
22+
## serve imagecache files directly or redirect to drupal if they do not exist.
23+
location ~* ^.+.(xsl|xml)$ {
24+
access_log off;
25+
expires 1d;
26+
try_files $uri @drupal;
27+
}
28+
29+
## Images and static content is treated different
30+
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
31+
access_log off;
32+
expires 30d;
33+
}
934

1035
location / {
11-
try_files $uri $uri/ /index.php?q=$uri&$args;
36+
index index.php;
37+
# This is cool because no php is touched for static content
38+
try_files $uri $uri/ @rewrite;
39+
expires max;
1240
}
1341

14-
error_page 404 /404.html;
15-
error_page 500 502 503 504 /50x.html;
16-
location = /50x.html {
17-
root /var/www/site_a;
42+
location @drupal {
43+
rewrite ^/(.*)$ /index.php?q=$1 last;
1844
}
1945

20-
location ~ [^/]\.php(/|$) {
21-
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
22-
if (!-f $document_root$fastcgi_script_name) {
23-
return 404;
24-
}
2546

47+
location @rewrite {
48+
# Some modules enforce no slash (/) at the end of the URL
49+
# Else this rewrite block wouldn't be needed (GlobalRedirect)
50+
rewrite ^/(.*)$ /index.php?q=$1;
51+
}
52+
53+
location ~ .php$ {
2654
fastcgi_pass php-upstream;
2755
fastcgi_index index.php;
2856
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

0 commit comments

Comments
 (0)