nginx.conf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. map $http_upgrade $connection_upgrade {
  2. default upgrade;
  3. '' close;
  4. }
  5. upstream backend {
  6. server 127.0.0.1:3000 fail_timeout=0;
  7. }
  8. upstream streaming {
  9. server 127.0.0.1:4000 fail_timeout=0;
  10. }
  11. proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=CACHE:10m inactive=7d max_size=1g;
  12. server {
  13. listen 80;
  14. listen [::]:80;
  15. server_name example.com;
  16. root /home/mastodon/live/public;
  17. location /.well-known/acme-challenge/ { allow all; }
  18. location / { return 301 https://$host$request_uri; }
  19. }
  20. server {
  21. listen 443 ssl http2;
  22. listen [::]:443 ssl http2;
  23. server_name example.com;
  24. ssl_protocols TLSv1.2 TLSv1.3;
  25. ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
  26. ssl_prefer_server_ciphers on;
  27. ssl_session_cache shared:SSL:10m;
  28. ssl_session_tickets off;
  29. # Uncomment these lines once you acquire a certificate:
  30. # ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  31. # ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  32. keepalive_timeout 70;
  33. sendfile on;
  34. client_max_body_size 80m;
  35. root /home/mastodon/live/public;
  36. gzip on;
  37. gzip_disable "msie6";
  38. gzip_vary on;
  39. gzip_proxied any;
  40. gzip_comp_level 6;
  41. gzip_buffers 16 8k;
  42. gzip_http_version 1.1;
  43. gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml image/x-icon;
  44. add_header Strict-Transport-Security "max-age=31536000" always;
  45. location / {
  46. try_files $uri @proxy;
  47. }
  48. location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) {
  49. add_header Cache-Control "public, max-age=31536000, immutable";
  50. add_header Strict-Transport-Security "max-age=31536000" always;
  51. add_header X-Content-Type-Options nosniff;
  52. add_header Content-Security-Policy "default-src 'none'; form-action 'none'";
  53. try_files $uri @proxy;
  54. }
  55. location /sw.js {
  56. add_header Cache-Control "public, max-age=0";
  57. add_header Strict-Transport-Security "max-age=31536000" always;
  58. add_header X-Content-Type-Options nosniff;
  59. try_files $uri @proxy;
  60. }
  61. location @proxy {
  62. proxy_set_header Host $host;
  63. proxy_set_header X-Real-IP $remote_addr;
  64. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  65. proxy_set_header X-Forwarded-Proto $scheme;
  66. proxy_set_header Proxy "";
  67. proxy_pass_header Server;
  68. proxy_pass http://backend;
  69. proxy_buffering on;
  70. proxy_redirect off;
  71. proxy_http_version 1.1;
  72. proxy_set_header Upgrade $http_upgrade;
  73. proxy_set_header Connection $connection_upgrade;
  74. proxy_cache CACHE;
  75. proxy_cache_valid 200 7d;
  76. proxy_cache_valid 410 24h;
  77. proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  78. add_header X-Cached $upstream_cache_status;
  79. add_header Strict-Transport-Security "max-age=31536000" always;
  80. tcp_nodelay on;
  81. }
  82. location /api/v1/streaming {
  83. proxy_set_header Host $host;
  84. proxy_set_header X-Real-IP $remote_addr;
  85. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  86. proxy_set_header X-Forwarded-Proto $scheme;
  87. proxy_set_header Proxy "";
  88. proxy_pass http://streaming;
  89. proxy_buffering off;
  90. proxy_redirect off;
  91. proxy_http_version 1.1;
  92. proxy_set_header Upgrade $http_upgrade;
  93. proxy_set_header Connection $connection_upgrade;
  94. tcp_nodelay on;
  95. }
  96. error_page 500 501 502 503 504 /500.html;
  97. }