|
| 1 | +server { |
| 2 | + listen ${NGINX_PORT}; |
| 3 | + server_name localhost; |
| 4 | + |
| 5 | + root ${NGINX_WEB_ROOT}; |
| 6 | + |
| 7 | + location = /favicon.ico { |
| 8 | + log_not_found off; |
| 9 | + access_log off; |
| 10 | + } |
| 11 | + |
| 12 | + location = /robots.txt { |
| 13 | + allow all; |
| 14 | + log_not_found off; |
| 15 | + access_log off; |
| 16 | + } |
| 17 | + |
| 18 | + location ~* \.(txt|log)$ { |
| 19 | + deny all; |
| 20 | + } |
| 21 | + |
| 22 | + location ~ \..*/.*\.php$ { |
| 23 | + return 403; |
| 24 | + } |
| 25 | + |
| 26 | + location ~ ^/sites/.*/private/ { |
| 27 | + return 403; |
| 28 | + } |
| 29 | + |
| 30 | + # Block access to scripts in site files directory |
| 31 | + location ~ ^/sites/[^/]+/files/.*\.php$ { |
| 32 | + deny all; |
| 33 | + } |
| 34 | + |
| 35 | + # Block access to "hidden" files and directories whose names begin with a |
| 36 | + # period. |
| 37 | + location ~ (^|/)\. { |
| 38 | + return 403; |
| 39 | + } |
| 40 | + |
| 41 | + location / { |
| 42 | + try_files $uri /index.php?$query_string; |
| 43 | + } |
| 44 | + |
| 45 | + location @rewrite { |
| 46 | + rewrite ^ /index.php; |
| 47 | + } |
| 48 | + |
| 49 | + # Don't allow direct access to PHP files in the vendor directory. |
| 50 | + location ~ /vendor/.*\.php$ { |
| 51 | + deny all; |
| 52 | + return 404; |
| 53 | + } |
| 54 | + |
| 55 | + # Protect files and directories from prying eyes. |
| 56 | + location ~* \.(engine|inc|install|make|module|profile|po|sh|.*sql|.tar|.gz|.bz2|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)$ { |
| 57 | + deny all; |
| 58 | + return 404; |
| 59 | + } |
| 60 | + |
| 61 | + location ~ '\.php$|^/update.php' { |
| 62 | + include fastcgi_params; |
| 63 | + |
| 64 | + fastcgi_buffers 16 32k; |
| 65 | + fastcgi_buffer_size 64k; |
| 66 | + fastcgi_busy_buffers_size 64k; |
| 67 | + |
| 68 | + fastcgi_split_path_info ^(.+?\.php)(|/.*)$; |
| 69 | + |
| 70 | + # Ensure the php file exists. Mitigates CVE-2019-11043 |
| 71 | + try_files $fastcgi_script_name =404; |
| 72 | + |
| 73 | + fastcgi_param HTTP_PROXY ""; |
| 74 | + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 75 | + fastcgi_param PATH_INFO $fastcgi_path_info; |
| 76 | + fastcgi_param QUERY_STRING $query_string; |
| 77 | + |
| 78 | + fastcgi_intercept_errors on; |
| 79 | + fastcgi_pass ${NGINX_FPM_SERVICE}; |
| 80 | + } |
| 81 | + |
| 82 | + # Enforce clean URLs |
| 83 | + # |
| 84 | + # Removes index.php from urls like www.example.com/index.php/my-page --> www.example.com/my-page |
| 85 | + # Could be done with 301 for permanent or other redirect codes. |
| 86 | + if ($request_uri ~* "^(.*/)index\.php/(.*)") { |
| 87 | + return 307 $1$2; |
| 88 | + } |
| 89 | + |
| 90 | + error_log /dev/stderr; |
| 91 | + access_log /dev/stdout main; |
| 92 | +} |
0 commit comments