nginx.conf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. try_files $uri @proxy;
  52. }
  53. location /sw.js {
  54. add_header Cache-Control "public, max-age=0";
  55. add_header Strict-Transport-Security "max-age=31536000" always;
  56. try_files $uri @proxy;
  57. }
  58. location @proxy {
  59. proxy_set_header Host $host;
  60. proxy_set_header X-Real-IP $remote_addr;
  61. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  62. proxy_set_header X-Forwarded-Proto $scheme;
  63. proxy_set_header Proxy "";
  64. proxy_pass_header Server;
  65. proxy_pass http://backend;
  66. proxy_buffering on;
  67. proxy_redirect off;
  68. proxy_http_version 1.1;
  69. proxy_set_header Upgrade $http_upgrade;
  70. proxy_set_header Connection $connection_upgrade;
  71. proxy_cache CACHE;
  72. proxy_cache_valid 200 7d;
  73. proxy_cache_valid 410 24h;
  74. proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  75. add_header X-Cached $upstream_cache_status;
  76. add_header Strict-Transport-Security "max-age=31536000" always;
  77. tcp_nodelay on;
  78. }
  79. location /api/v1/streaming {
  80. proxy_set_header Host $host;
  81. proxy_set_header X-Real-IP $remote_addr;
  82. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  83. proxy_set_header X-Forwarded-Proto $scheme;
  84. proxy_set_header Proxy "";
  85. proxy_pass http://streaming;
  86. proxy_buffering off;
  87. proxy_redirect off;
  88. proxy_http_version 1.1;
  89. proxy_set_header Upgrade $http_upgrade;
  90. proxy_set_header Connection $connection_upgrade;
  91. tcp_nodelay on;
  92. }
  93. error_page 500 501 502 503 504 /500.html;
  94. }