drupal-ssl.nginxconf 4.0 KB

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