@@ -79,17 +79,123 @@ server {
7979 index index.php;
8080
8181 location / {
82- try_files $uri /index.php$is_args$args;
83- }
84-
85- location ~ \.php$ {
86- #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
87- include fastcgi_params;
88- fastcgi_index index.php;
89- fastcgi_pass docker_drupal;
90- #The following parameter can be also included in fastcgi_params file
91- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
82+ try_files $uri $uri/ /index.php$is_args$args;
9283 }
84+ location @rewrite {
85+ #rewrite ^/(.*)$ /index.php?q=$1; # For Drupal <= 6
86+ rewrite ^ /index.php; # For Drupal >= 7
87+ }
88+
89+ # Don't allow direct access to PHP files in the vendor directory.
90+ location ~ /vendor/.*\.php$ {
91+ deny all;
92+ return 404;
93+ }
94+
95+ # Protect files and directories from prying eyes.
96+ location ~* \.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config)$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$ {
97+ deny all;
98+ return 404;
99+ }
100+
101+ # In Drupal 8, we must also match new paths where the '.php' appears in
102+ # the middle, such as update.php/selection. The rule we use is strict,
103+ # and only allows this pattern with the update.php front controller.
104+ # This allows legacy path aliases in the form of
105+ # blog/index.php/legacy-path to continue to route to Drupal nodes. If
106+ # you do not have any paths like that, then you might prefer to use a
107+ # laxer rule, such as:
108+ # location ~ \.php(/|$) {
109+ # The laxer rule will continue to work if Drupal uses this new URL
110+ # pattern with front controllers other than update.php in a future
111+ # release.
112+ location ~ '\.php$|^/update.php' {
113+ fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
114+ # Ensure the php file exists. Mitigates CVE-2019-11043
115+ try_files $fastcgi_script_name =404;
116+ # Security note: If you're running a version of PHP older than the
117+ # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
118+ # See http://serverfault.com/q/627903/94922 for details.
119+ include fastcgi_params;
120+ fastcgi_index index.php;
121+ # Block httpoxy attacks. See https://httpoxy.org/.
122+ fastcgi_param HTTP_PROXY "";
123+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
124+ fastcgi_param PATH_INFO $fastcgi_path_info;
125+ fastcgi_param QUERY_STRING $query_string;
126+ fastcgi_intercept_errors on;
127+ # PHP 5 socket location.
128+ #fastcgi_pass unix:/var/run/php5-fpm.sock;
129+ # PHP 7 socket location.
130+ fastcgi_pass docker_drupal;
131+ }
132+
133+ location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
134+ try_files $uri @rewrite;
135+ expires max;
136+ log_not_found off;
137+ }
138+
139+ # Fighting with Styles? This little gem is amazing.
140+ # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
141+ location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
142+ try_files $uri @rewrite;
143+ }
144+
145+ # Handle private files through Drupal. Private file's path can come
146+ # with a language prefix.
147+ location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
148+ try_files $uri /index.php?$query_string;
149+ }
150+
151+ # Enforce clean URLs
152+ # Removes index.php from urls like www.example.com/index.php/my-page --> www.example.com/my-page
153+ # Could be done with 301 for permanent or other redirect codes.
154+ if ($request_uri ~* "^(.*/)index\.php/(.*)") {
155+ return 307 $1$2;
156+ }
157+ #
158+ location = /favicon.ico {
159+ log_not_found off;
160+ access_log off;
161+ }
162+
163+ location = /robots.txt {
164+ allow all;
165+ log_not_found off;
166+ access_log off;
167+ }
168+
169+ # Very rarely should these ever be accessed outside of your lan
170+ location ~* \.(txt|log)$ {
171+ allow 192.168.0.0/16;
172+ deny all;
173+ }
174+
175+ location ~ \..*/.*\.php$ {
176+ return 403;
177+ }
178+
179+ location ~ ^/sites/.*/private/ {
180+ return 403;
181+ }
182+
183+ # Block access to scripts in site files directory
184+ location ~ ^/sites/[^/]+/files/.*\.php$ {
185+ deny all;
186+ }
187+
188+ # Allow "Well-Known URIs" as per RFC 5785
189+ location ~* ^/.well-known/ {
190+ allow all;
191+ }
192+
193+ # Block access to "hidden" files and directories whose names begin with a
194+ # period. This includes directories used by version control systems such
195+ # as Subversion or Git to store control files.
196+ location ~ (^|/)\. {
197+ return 403;
198+ }
93199 #
94200 access_log off;
95201 error_log /var/log/nginx/${NGINX_HOST}-90.error.log error;
0 commit comments