Last active
December 27, 2018 23:29
-
-
Save skyred/4248423 to your computer and use it in GitHub Desktop.
Nginx config for Drupal 7 and Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
server_name www.insready.com; | |
root /srv/www/insready.com/public_html; ## <-- Your only path reference. | |
access_log /srv/www/insready.com/logs/access.log; | |
error_log /srv/www/insready.com/logs/error.log; | |
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)$ { | |
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$|^/update.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/php5-fpm.sock; | |
fastcgi_cache microcache; | |
fastcgi_cache_bypass $no_cache; | |
fastcgi_no_cache $no_cache; | |
# Set cache key to include identifying components | |
fastcgi_cache_key $cache_uid@$host$request_uri$request_method; | |
fastcgi_cache_valid 200 301 15s; | |
fastcgi_cache_valid 302 1m; | |
fastcgi_cache_valid 404 1s; | |
fastcgi_cache_min_uses 1; | |
fastcgi_cache_use_stale error timeout invalid_header updating http_500; | |
fastcgi_ignore_headers Cache-Control Expires; | |
fastcgi_pass_header Set-Cookie; | |
fastcgi_pass_header Cookie; | |
## Add a cache miss/hit status header. | |
add_header X-Micro-Cache $upstream_cache_status; | |
## To avoid any interaction with the cache control headers we expire | |
## everything on this location immediately. | |
expires epoch; | |
## Cache locking mechanism for protecting the backend of too many | |
## simultaneous requests. | |
fastcgi_cache_lock on; | |
} | |
location ~* ^(?!/system/files).*\.(js|css|png|jpg|jpeg|gif|ico|ttf|svg)$ { | |
## If the image does not exist, maybe it must be generated by drupal (imagecache) | |
try_files $uri @rewrite; | |
expires 7d; | |
log_not_found off; | |
} | |
## private files protection | |
location ~ ^/sites/.*/private/ { | |
access_log off; | |
deny all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment