Skip to content

Instantly share code, notes, and snippets.

@krabello
Created May 12, 2016 13:41
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 krabello/1015243a9efae7a797f80c26ae895001 to your computer and use it in GitHub Desktop.
Save krabello/1015243a9efae7a797f80c26ae895001 to your computer and use it in GitHub Desktop.
Drupal 8 Nginx Configuration
server {
listen 80; # redundant in new nginx versions
server_name domain.com;
root /var/www/html/drupal;
access_log off;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
location ~ \..*/.*\.php$ {
return 403;
}
# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}
location / {
try_files $uri @rewrite;
}
location @rewrite {
rewrite ^ /index.php;
}
# Added this to enable installing themes
rewrite ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1;
location ~ \.php$ {
set $no_cache "";
if ($request_method !~ ^(GET|HEAD)$) {
set $no_cache "1";
}
if ($no_cache = "1") {
add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
add_header X-Microcachable "0";
}
if ($http_cookie ~ SESS) {
set $no_cache "1";
}
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
#fastcgi_cache microcache;
fastcgi_cache_key $server_name|$request_uri;
fastcgi_cache_valid 404 30m;
fastcgi_cache_valid 200 1s;
fastcgi_max_temp_file_size 1M;
fastcgi_cache_use_stale updating;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_index index.php;
include fastcgi_params;
}
#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;
}
}
@M1r1k
Copy link

M1r1k commented Jun 19, 2018

location ~ ../..php$

WARNING, this is posted all over the web but only works for hidden directories:
see https://drupal.stackexchange.com/a/260534/16651

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