nginx.conf 3.0 KB

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