nginx.conf 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. location / {
  45. try_files $uri @proxy;
  46. }
  47. # If Docker is used for deployment and Rails serves static files,
  48. # then needed must replace line `try_files $uri =404;` with `try_files $uri @proxy;`.
  49. location = /sw.js {
  50. add_header Cache-Control "public, max-age=604800, must-revalidate";
  51. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  52. try_files $uri =404;
  53. }
  54. location ~ ^/assets/ {
  55. add_header Cache-Control "public, max-age=2419200, must-revalidate";
  56. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  57. try_files $uri =404;
  58. }
  59. location ~ ^/avatars/ {
  60. add_header Cache-Control "public, max-age=2419200, must-revalidate";
  61. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  62. try_files $uri =404;
  63. }
  64. location ~ ^/emoji/ {
  65. add_header Cache-Control "public, max-age=2419200, must-revalidate";
  66. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  67. try_files $uri =404;
  68. }
  69. location ~ ^/headers/ {
  70. add_header Cache-Control "public, max-age=2419200, must-revalidate";
  71. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  72. try_files $uri =404;
  73. }
  74. location ~ ^/packs/ {
  75. add_header Cache-Control "public, max-age=2419200, must-revalidate";
  76. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  77. try_files $uri =404;
  78. }
  79. location ~ ^/shortcuts/ {
  80. add_header Cache-Control "public, max-age=2419200, must-revalidate";
  81. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  82. try_files $uri =404;
  83. }
  84. location ~ ^/sounds/ {
  85. add_header Cache-Control "public, max-age=2419200, must-revalidate";
  86. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  87. try_files $uri =404;
  88. }
  89. location ~ ^/system/ {
  90. add_header Cache-Control "public, max-age=2419200, immutable";
  91. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  92. try_files $uri =404;
  93. }
  94. location ^~ /api/v1/streaming {
  95. proxy_set_header Host $host;
  96. proxy_set_header X-Real-IP $remote_addr;
  97. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  98. proxy_set_header X-Forwarded-Proto $scheme;
  99. proxy_set_header Proxy "";
  100. proxy_pass http://streaming;
  101. proxy_buffering off;
  102. proxy_redirect off;
  103. proxy_http_version 1.1;
  104. proxy_set_header Upgrade $http_upgrade;
  105. proxy_set_header Connection $connection_upgrade;
  106. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  107. tcp_nodelay on;
  108. }
  109. location @proxy {
  110. proxy_set_header Host $host;
  111. proxy_set_header X-Real-IP $remote_addr;
  112. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  113. proxy_set_header X-Forwarded-Proto $scheme;
  114. proxy_set_header Proxy "";
  115. proxy_pass_header Server;
  116. proxy_pass http://backend;
  117. proxy_buffering on;
  118. proxy_redirect off;
  119. proxy_http_version 1.1;
  120. proxy_set_header Upgrade $http_upgrade;
  121. proxy_set_header Connection $connection_upgrade;
  122. proxy_cache CACHE;
  123. proxy_cache_valid 200 7d;
  124. proxy_cache_valid 410 24h;
  125. proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  126. add_header X-Cached $upstream_cache_status;
  127. tcp_nodelay on;
  128. }
  129. error_page 404 500 501 502 503 504 /500.html;
  130. }