Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update drupal nginx.conf #490

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 26 additions & 10 deletions images/nginx-drupal/drupal.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### Nginx configuration for Drupal.
## Nginx configuration for Drupal
## @see https://www.drupal.org/project/drupal/issues/2937161
server {
include /etc/nginx/conf.d/drupal/server_prepend*.conf;

Expand All @@ -9,10 +10,6 @@ server {
root /app/${WEBROOT:-};
index index.php;

## rewriting /index.php to / because after https://www.drupal.org/node/2599326
## autocomplete URLs are forced to go to index.php
rewrite ^/index.php / last;

## The 'default' location.
location / {
include /etc/nginx/conf.d/drupal/location_prepend*.conf;
Expand All @@ -27,10 +24,11 @@ server {
}

## Do not allow access to .txt and .md unless inside sites/*/files/
location ~* ^(?!.+sites\/.+\/files\/).+\.(txt|md)$ {
location ~* ^(?!.+sites\/.+\/files\/).+\.(txt|md|log)$ {
deny all;
access_log off;
log_not_found off;
return 404;
}

## Replicate the Apache <FilesMatch> directive of Drupal standard
Expand All @@ -46,12 +44,19 @@ server {
## Expiring per default for four weeks and one second, Drupal will overwrite that if necessary
expires ${NGINX_DEFAULT_EXPIRES:-2628001s};

## Disallow access to any dot files, but send the request to Drupal
location ~* /\. {
try_files /dev/null @drupal;
## Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}

### Directives for installing drupal.
## 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;
}

## Directives for installing drupal.
location ~* ^(/install.php|/core/install.php) {
try_files /dev/null @php;
}
Expand All @@ -61,6 +66,12 @@ server {
try_files /dev/null @drupal;
}

## Enforce clean URLs
## Removes index.php from urls like www.example.com/index.php/my-page --> www.example.com/my-page
location ~* (.*/)index\.php/(.*) {
return 301 $1$2$is_args$args;
}

## Try to find a file with given URL, if not pass to Drupal
try_files $uri @drupal;

Expand Down Expand Up @@ -100,34 +111,39 @@ server {
deny all;
access_log off;
log_not_found off;
return 404;
}

## Disallow access to backup directory.
location ^~ /backup/ {
deny all;
access_log off;
log_not_found off;
return 404;
}

## Disallow access to vagrant directory.
location ^~ /vagrant/ {
deny all;
access_log off;
log_not_found off;
return 404;
}

## Disallow access to vendor directory.
location ^~ /core/vendor/ {
deny all;
access_log off;
log_not_found off;
return 404;
}

## Disallow access to vendor directory.
location ^~ /vendor/ {
deny all;
access_log off;
log_not_found off;
return 404;
}

## Support for the robotstxt module
Expand Down
3 changes: 1 addition & 2 deletions images/nginx-drupal/drupal/favicon.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
## Support for favicon. Return an 1x1 transparent GIF if it doesn't
## exist.
## Support for favicon. Return an 1x1 transparent GIF if it doesn't exist.
location = /favicon.ico {
expires 30d;
try_files /favicon.ico @empty;
Expand Down