nginx-ddev-site.conf 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # ddev GravCMS config
  2. # You can override ddev's configuration by placing an edited copy
  3. # of this config (or one of the other ones) in .ddev/nginx-site.conf
  4. # See https://ddev.readthedocs.io/en/latest/users/extend/customization-extendibility/#providing-custom-nginx-configuration
  5. # Set https to 'on' if x-forwarded-proto is https
  6. map $http_x_forwarded_proto $fcgi_https {
  7. default off;
  8. https on;
  9. }
  10. server {
  11. listen 80; ## listen for ipv4; this line is default and implied
  12. listen [::]:80 default ipv6only=on; ## listen for ipv6
  13. # The NGINX_DOCROOT variable is substituted with
  14. # its value when the container is started.
  15. root $NGINX_DOCROOT;
  16. index index.php index.htm index.html;
  17. # Make site accessible from http://localhost/
  18. server_name _;
  19. # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
  20. sendfile off;
  21. error_log /var/log/nginx/error.log info;
  22. access_log /var/log/nginx/access.log;
  23. location / {
  24. absolute_redirect off;
  25. try_files $uri $uri/ /index.php?$query_string;
  26. }
  27. # pass the PHP scripts to FastCGI server listening on socket
  28. location ~ \.php$ {
  29. try_files $uri =404;
  30. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  31. fastcgi_pass unix:/run/php-fpm.sock;
  32. fastcgi_buffers 16 16k;
  33. fastcgi_buffer_size 32k;
  34. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  35. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  36. fastcgi_index index.php;
  37. include fastcgi_params;
  38. fastcgi_intercept_errors on;
  39. # fastcgi_read_timeout should match max_execution_time in php.ini
  40. fastcgi_read_timeout 10m;
  41. fastcgi_param SERVER_NAME $host;
  42. fastcgi_param HTTPS $fcgi_https;
  43. }
  44. # Expire rules for static content
  45. # Feed
  46. location ~* \.(?:rss|atom|cache)$ {
  47. expires 1h;
  48. }
  49. # Media: images, icons, video, audio, HTC
  50. location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  51. expires 1M;
  52. access_log off;
  53. add_header Cache-Control "public";
  54. }
  55. # Prevent clients from accessing hidden files (starting with a dot)
  56. # This is particularly important if you store .htpasswd files in the site hierarchy
  57. # Access to `/.well-known/` is allowed.
  58. # https://www.mnot.net/blog/2010/04/07/well-known
  59. # https://tools.ietf.org/html/rfc5785
  60. location ~* /\.(?!well-known\/) {
  61. deny all;
  62. }
  63. # Prevent clients from accessing to backup/config/source files
  64. location ~* (?:\.(?:bak|conf|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$ {
  65. deny all;
  66. }
  67. ## Begin - Security
  68. # deny all direct access for these folders
  69. location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
  70. # deny running scripts inside core system folders
  71. location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
  72. # deny running scripts inside user folder
  73. location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
  74. # deny access to specific files in the root folder
  75. location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }
  76. ## End - Security
  77. ## provide a health check endpoint
  78. location /healthcheck {
  79. access_log off;
  80. stub_status on;
  81. keepalive_timeout 0; # Disable HTTP keepalive
  82. return 200;
  83. }
  84. error_page 400 401 /40x.html;
  85. location = /40x.html {
  86. root /usr/share/nginx/html;
  87. }
  88. location ~ ^/(fpmstatus|ping)$ {
  89. access_log off;
  90. stub_status on;
  91. keepalive_timeout 0; # Disable HTTP keepalive
  92. allow 127.0.0.1;
  93. allow all;
  94. fastcgi_index index.php;
  95. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  96. include fastcgi_params;
  97. fastcgi_pass unix:/run/php-fpm.sock;
  98. }
  99. }