drupal.nginxconf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/
  2. server {
  3. listen 80;
  4. listen [::]:80;
  5. server_name DOMAIN.LTD;
  6. root /var/www/DOMAIN.LTD/public_html;
  7. charset utf-8;
  8. location = /favicon.ico {
  9. access_log off;
  10. log_not_found off;
  11. }
  12. location = /robots.txt {
  13. allow all;
  14. access_log off;
  15. log_not_found off;
  16. }
  17. location ~ \..*/.*\.php$ {
  18. return 403;
  19. }
  20. location ~ ^/sites/.*/private/ {
  21. return 403;
  22. }
  23. # Block access to scripts in site files directory
  24. location ~ ^/sites/[^/]+/files/.*\.php$ {
  25. deny all;
  26. }
  27. # Allow "Well-Known URIs" as per RFC 5785
  28. location ~* ^/.well-known/ {
  29. allow all;
  30. }
  31. # Block access to "hidden" files and directories whose names begin with a
  32. # period. This includes directories used by version control systems such
  33. # as Subversion or Git to store control files.
  34. location ~ (^|/)\. {
  35. return 403;
  36. }
  37. location / {
  38. # try_files $uri @rewrite; # For Drupal <= 6
  39. try_files $uri /index.php?$query_string; # For Drupal >= 7
  40. }
  41. location @rewrite {
  42. rewrite ^/(.*)$ /index.php?q=$1;
  43. }
  44. # Don't allow direct access to PHP files in the vendor directory.
  45. location ~ /vendor/.*\.php$ {
  46. deny all;
  47. return 404;
  48. }
  49. location ~ /\.ht {
  50. deny all;
  51. }
  52. access_log on;
  53. error_log /var/www/DOMAIN.LTD/log/error.log;
  54. sendfile off;
  55. client_max_body_size 100m;
  56. # In Drupal 8, we must also match new paths where the '.php' appears in
  57. # the middle, such as update.php/selection. The rule we use is strict,
  58. # and only allows this pattern with the update.php front controller.
  59. # This allows legacy path aliases in the form of
  60. # blog/index.php/legacy-path to continue to route to Drupal nodes. If
  61. # you do not have any paths like that, then you might prefer to use a
  62. # laxer rule, such as:
  63. # location ~ \.php(/|$) {
  64. # The laxer rule will continue to work if Drupal uses this new URL
  65. # pattern with front controllers other than update.php in a future
  66. # release.
  67. location ~ '\.php$|^/update.php' {
  68. # fastcgi_split_path_info ^(.+\.php)(/.+)$;
  69. fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
  70. include fastcgi_params;
  71. # Block httpoxy attacks. See https://httpoxy.org/.
  72. fastcgi_param HTTP_PROXY "";
  73. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  74. fastcgi_param PATH_INFO $fastcgi_path_info;
  75. fastcgi_param QUERY_STRING $query_string;
  76. fastcgi_intercept_errors on;
  77. # fastcgi_buffer_size 16k;
  78. # fastcgi_buffers 4 16k;
  79. fastcgi_pass unix:/run/php/php8.2-fpm.sock;
  80. }
  81. # Fighting with Styles? This little gem is amazing.
  82. # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
  83. location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
  84. try_files $uri @rewrite;
  85. }
  86. # Handle private files through Drupal. Private file's path can come
  87. # with a language prefix.
  88. location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
  89. try_files $uri /index.php?$query_string;
  90. }
  91. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
  92. try_files $uri @rewrite;
  93. expires max;
  94. log_not_found off;
  95. }
  96. # website should not be displayed inside a <frame>, an <iframe> or an <object>
  97. add_header X-Frame-Options SAMEORIGIN;
  98. }