nginx.conf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. server {
  2. # Listen only on port 81 for localhost, and nothing else.
  3. server_name 127.0.0.1;
  4. listen 127.0.0.1:81 default_server;
  5. charset utf-8;
  6. # Certbot's folder used for the ACME challenge response.
  7. location ^~ /.well-known/acme-challenge {
  8. default_type text/plain;
  9. root /var/www/certbot;
  10. try_files $uri =404;
  11. }
  12. }
  13. server {
  14. listen [::]:80;
  15. listen 80;
  16. server_name %hostname%;
  17. location '/.well-known/acme-challenge' {
  18. proxy_pass http://localhost:81;
  19. }
  20. # redirect all traffic to HTTPS
  21. rewrite ^ https://$host$request_uri? permanent;
  22. }
  23. server {
  24. listen [::]:443 ssl http2;
  25. listen 443 ssl http2;
  26. ssl_certificate /etc/letsencrypt/live/%hostname%/fullchain.pem;
  27. ssl_certificate_key /etc/letsencrypt/live/%hostname%/privkey.pem;
  28. # Let's Encrypt best practices
  29. include /etc/letsencrypt/options-ssl-nginx.conf;
  30. ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
  31. root /var/www/social/public;
  32. # Server name
  33. server_name %hostname%;
  34. # Index
  35. index index.php;
  36. # X-Accel/X-Sendfile. Still needs to be enabled in the config
  37. location /file {
  38. internal;
  39. root /var/www/social;
  40. }
  41. location /.well-known/acme-challenge/ {
  42. allow all;
  43. root /var/www/certbot;
  44. try_files $uri =404;
  45. break;
  46. }
  47. # PHP
  48. location ~ ^/(index|install)\.php(/.*)?$ {
  49. include fastcgi_params;
  50. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  51. set $path_info $fastcgi_path_info;
  52. try_files $fastcgi_script_name =404;
  53. fastcgi_pass php:9000;
  54. fastcgi_index index.php;
  55. fastcgi_param PATH_INFO $path_info;
  56. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  57. }
  58. # Don't allow any PHP file other than index.php to be executed
  59. # This will ensure that nor config.php nor plugin files with eventual hardcoded security information are downloadable
  60. # And this is better than allowing php files to be executed in case of forgotten `if (!defined('GNUSOCIAL')) { exit(1); }`
  61. location ~ \.php$ {
  62. deny all;
  63. }
  64. # Location
  65. location / {
  66. try_files $uri $uri/ @index_handler;
  67. }
  68. # Fancy URLs
  69. error_page 404 @index_handler;
  70. location @index_handler {
  71. rewrite ^(.*)$ /index.php?p=$1 last;
  72. }
  73. # Restrict access that is unnecessary anyway
  74. location ~ /\.(ht|git) {
  75. deny all;
  76. }
  77. #
  78. # Hardening (optional)
  79. #
  80. add_header Strict-Transport-Security "max-age=15768000; preload;";
  81. add_header X-Content-Type-Options nosniff;
  82. add_header Referrer-Policy strict-origin-when-cross-origin;
  83. add_header Content-Security-Policy "default-src 'self' 'unsafe-inline'; frame-ancestors 'self'; form-action 'self'; style-src 'self' 'unsafe-inline'; img-src * blob: data:;";
  84. add_header X-Permitted-Cross-Domain-Policies none;
  85. add_header X-Robots-Tag all; # Not really hardening, just here for strictness purposes
  86. client_max_body_size 15M;
  87. client_body_buffer_size 128k;
  88. gzip_vary on;
  89. location ~* \.(?:css|js|woff|svg|gif|png|webp|ttf|ico|jpe?g)$ {
  90. gzip on;
  91. gzip_comp_level 4;
  92. add_header Cache-Control "public";
  93. expires 30d;
  94. access_log off;
  95. log_not_found off;
  96. }
  97. }