|
| 1 | +# @see https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/ |
| 2 | +server { |
| 3 | + listen 80; |
| 4 | + server_name localhost; |
| 5 | + |
| 6 | + root /app; |
| 7 | + |
| 8 | + location = /favicon.ico { |
| 9 | + log_not_found off; |
| 10 | + access_log off; |
| 11 | + } |
| 12 | + |
| 13 | + location = /robots.txt { |
| 14 | + allow all; |
| 15 | + log_not_found off; |
| 16 | + access_log off; |
| 17 | + } |
| 18 | + |
| 19 | + # Very rarely should these ever be accessed outside of your lan |
| 20 | + location ~* \.(txt|log)$ { |
| 21 | + allow 192.168.0.0/16; |
| 22 | + deny all; |
| 23 | + } |
| 24 | + |
| 25 | + location ~ \..*/.*\.php$ { |
| 26 | + return 403; |
| 27 | + } |
| 28 | + |
| 29 | + location ~ ^/sites/.*/private/ { |
| 30 | + return 403; |
| 31 | + } |
| 32 | + |
| 33 | + # Block access to scripts in site files directory |
| 34 | + location ~ ^/sites/[^/]+/files/.*\.php$ { |
| 35 | + deny all; |
| 36 | + } |
| 37 | + |
| 38 | + # Allow "Well-Known URIs" as per RFC 5785 |
| 39 | + location ~* ^/.well-known/ { |
| 40 | + allow all; |
| 41 | + } |
| 42 | + |
| 43 | + # Block access to "hidden" files and directories whose names begin with a |
| 44 | + # period. This includes directories used by version control systems such |
| 45 | + # as Subversion or Git to store control files. |
| 46 | + location ~ (^|/)\. { |
| 47 | + return 403; |
| 48 | + } |
| 49 | + |
| 50 | + location / { |
| 51 | + # try_files $uri @rewrite; # For Drupal <= 6 |
| 52 | + try_files $uri /index.php?$query_string; # For Drupal >= 7 |
| 53 | + } |
| 54 | + |
| 55 | + location @rewrite { |
| 56 | + rewrite ^/(.*)$ /index.php?q=$1; |
| 57 | + } |
| 58 | + |
| 59 | + # Don't allow direct access to PHP files in the vendor directory. |
| 60 | + location ~ /vendor/.*\.php$ { |
| 61 | + deny all; |
| 62 | + return 404; |
| 63 | + } |
| 64 | + |
| 65 | + # In Drupal 8, we must also match new paths where the '.php' appears in |
| 66 | + # the middle, such as update.php/selection. The rule we use is strict, |
| 67 | + # and only allows this pattern with the update.php front controller. |
| 68 | + # This allows legacy path aliases in the form of |
| 69 | + # blog/index.php/legacy-path to continue to route to Drupal nodes. If |
| 70 | + # you do not have any paths like that, then you might prefer to use a |
| 71 | + # laxer rule, such as: |
| 72 | + # location ~ \.php(/|$) { |
| 73 | + # The laxer rule will continue to work if Drupal uses this new URL |
| 74 | + # pattern with front controllers other than update.php in a future |
| 75 | + # release. |
| 76 | + location ~ '\.php$|^/update.php' { |
| 77 | + fastcgi_split_path_info ^(.+?\.php)(|/.*)$; |
| 78 | + # Security note: If you're running a version of PHP older than the |
| 79 | + # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini. |
| 80 | + # See http://serverfault.com/q/627903/94922 for details. |
| 81 | + include fastcgi_params; |
| 82 | + # Block httpoxy attacks. See https://httpoxy.org/. |
| 83 | + fastcgi_param HTTP_PROXY ""; |
| 84 | + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 85 | + fastcgi_param PATH_INFO $fastcgi_path_info; |
| 86 | + fastcgi_param QUERY_STRING $query_string; |
| 87 | + fastcgi_intercept_errors on; |
| 88 | + fastcgi_param PHP_VALUE "memory_limit = 512M"; |
| 89 | + fastcgi_pass phpfpm:9000; |
| 90 | + fastcgi_send_timeout 300; |
| 91 | + fastcgi_read_timeout 300; |
| 92 | + } |
| 93 | + |
| 94 | + # Fighting with Styles? This little gem is amazing. |
| 95 | + # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6 |
| 96 | + location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7 |
| 97 | + try_files $uri @rewrite; |
| 98 | + } |
| 99 | + |
| 100 | + # Handle private files through Drupal. Private file's path can come |
| 101 | + # with a language prefix. |
| 102 | + location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7 |
| 103 | + try_files $uri /index.php?$query_string; |
| 104 | + } |
| 105 | + |
| 106 | + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { |
| 107 | + try_files $uri @rewrite; |
| 108 | + expires max; |
| 109 | + log_not_found off; |
| 110 | + } |
| 111 | +} |
0 commit comments