Skip to content

Instantly share code, notes, and snippets.

@Jaesin
Last active April 20, 2021 16:13
Show Gist options
  • Save Jaesin/3d75e2f0e81b4d19579a to your computer and use it in GitHub Desktop.
Save Jaesin/3d75e2f0e81b4d19579a to your computer and use it in GitHub Desktop.
Drupal 8 Nginx configuration
# @file
# NGINX Configuration file for Drupal 8
# Redirect index to php.
location / {
try_files $uri @rewrite;
}
# Allow but don't log access to /favicon.ico and /robots.txt
location ~ (^/favicon\.ico$|^/robots\.txt$) {
access_log off;
allow all;
log_not_found off;
}
# Block access tot he vendor directory.
location ^~ /vendor/ {
deny all;
return 404;
}
# Allow / access to other core scripts.
location ~ ^/(install|rebuild|authorize)\.php$ {
rewrite ^/(.*)$ /core$uri last;
}
# Enable clean urls for update.php
location ~ ^/update\.php/.*$ {
rewrite ^ /update.php;
}
# Create the rewrite alias.
location @rewrite {
rewrite ^ /index.php;
}
# Deny direct access to yaml files, private files, and settings.php files.
location ~ ((^|/)\.|^.*\.yml$|^/sites/.*/private/|^/sites/default/files/php/|^/core/[^/]+/.*\.php$|^/sites/[^/]+/.*settings.*\.php$) {
return 404;
}
# Try to provide direct access to static assets, pass to drupal if an asset isn't avaiable.
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
# Provides direct access to image style generated file.
# This directive will pass the request to drupal if the image asset does not exist.
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
# Configure fastcgi for the site.
location ~ \.php$ {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/usr/local/var/run/php7-fcgi.sock;
fastcgi_read_timeout 2400;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_index index.php;
}
#server {
# listen 80;
# server_name foo.l;
#
# access_log /usr/local/var/log/nginx/foo.l.access.log combined;
# error_log /usr/local/var/log/nginx/foo.l.error.log;
#
# root /var/www/html;
#
# include apps/drupal-8.conf;
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment