|
| 1 | +# |
| 2 | +# @DCG: { |
| 3 | +# The configuration is based on official Nginx recipe. |
| 4 | +# See https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/ |
| 5 | +# |
| 6 | +# Check out Perusio's config for more delicate configuration. |
| 7 | +# See https://github.com/perusio/drupal-with-nginx |
| 8 | +# @DCG: } |
| 9 | +# |
| 10 | +server { |
| 11 | + server_name example.local; |
| 12 | + root /var/www/example.local/docroot; |
| 13 | + |
| 14 | + location = /favicon.ico { |
| 15 | + log_not_found off; |
| 16 | + access_log off; |
| 17 | + } |
| 18 | + |
| 19 | + location = /robots.txt { |
| 20 | + allow all; |
| 21 | + log_not_found off; |
| 22 | + access_log off; |
| 23 | + } |
| 24 | + |
| 25 | + # Very rarely should these ever be accessed. |
| 26 | + location ~* \.(make|txt|log|engine|inc|info|install|module|profile|po|pot|sh|sql|test|theme)$ { |
| 27 | + return 404; |
| 28 | + } |
| 29 | + |
| 30 | + location ~ \..*/.*\.php$ { |
| 31 | + return 404; |
| 32 | + } |
| 33 | + |
| 34 | + location ~ ^/sites/.*/private/ { |
| 35 | + return 403; |
| 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 404; |
| 48 | + } |
| 49 | + |
| 50 | + location / { |
| 51 | + try_files $uri /index.php?$query_string; |
| 52 | + } |
| 53 | + |
| 54 | + # Don't allow direct access to PHP files in the vendor directory. |
| 55 | + location ~ /vendor/.*\.php$ { |
| 56 | + deny all; |
| 57 | + return 404; |
| 58 | + } |
| 59 | + |
| 60 | + # In Drupal 8, we must also match new paths where the '.php' appears in |
| 61 | + # the middle, such as update.php/selection. The rule we use is strict, |
| 62 | + # and only allows this pattern with the update.php front controller. |
| 63 | + # This allows legacy path aliases in the form of |
| 64 | + # blog/index.php/legacy-path to continue to route to Drupal nodes. If |
| 65 | + # you do not have any paths like that, then you might prefer to use a |
| 66 | + # laxer rule, such as: |
| 67 | + # location ~ \.php(/|$) { |
| 68 | + # The laxer rule will continue to work if Drupal uses this new URL |
| 69 | + # pattern with front controllers other than update.php in a future |
| 70 | + # release. |
| 71 | + location ~ '\.php$|^/update.php' { |
| 72 | + fastcgi_split_path_info ^(.+?\.php)(|/.*)$; |
| 73 | + # Security note: If you're running a version of PHP older than the |
| 74 | + # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini. |
| 75 | + # See http://serverfault.com/q/627903/94922 for details. |
| 76 | + include fastcgi_params; |
| 77 | + # Block httpoxy attacks. See https://httpoxy.org/. |
| 78 | + fastcgi_param HTTP_PROXY ""; |
| 79 | + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 80 | + fastcgi_param PATH_INFO $fastcgi_path_info; |
| 81 | + fastcgi_intercept_errors on; |
| 82 | + fastcgi_pass unix:/run/php/php7.0-fpm.sock; |
| 83 | + } |
| 84 | + |
| 85 | + # Fighting with Styles? This little gem is amazing. |
| 86 | + location ~ ^/sites/.*/files/styles/ { |
| 87 | + try_files $uri @rewrite; |
| 88 | + } |
| 89 | + |
| 90 | + # Handle private files through Drupal. |
| 91 | + location ~ ^/system/files/ { |
| 92 | + try_files $uri /index.php?$query_string; |
| 93 | + } |
| 94 | + |
| 95 | + location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { |
| 96 | + expires max; |
| 97 | + log_not_found off; |
| 98 | + } |
| 99 | +} |
0 commit comments