You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.1 KiB

  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. # Uncomment these lines once you acquire a certificate:
  29. # ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  30. # ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  31. keepalive_timeout 70;
  32. sendfile on;
  33. client_max_body_size 80m;
  34. root /home/mastodon/live/public;
  35. gzip on;
  36. gzip_disable "msie6";
  37. gzip_vary on;
  38. gzip_proxied any;
  39. gzip_comp_level 6;
  40. gzip_buffers 16 8k;
  41. gzip_http_version 1.1;
  42. gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  43. add_header Strict-Transport-Security "max-age=31536000";
  44. location / {
  45. try_files $uri @proxy;
  46. }
  47. location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) {
  48. add_header Cache-Control "public, max-age=31536000, immutable";
  49. add_header Strict-Transport-Security "max-age=31536000";
  50. try_files $uri @proxy;
  51. }
  52. location /sw.js {
  53. add_header Cache-Control "public, max-age=0";
  54. add_header Strict-Transport-Security "max-age=31536000";
  55. try_files $uri @proxy;
  56. }
  57. location @proxy {
  58. proxy_set_header Host $host;
  59. proxy_set_header X-Real-IP $remote_addr;
  60. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  61. proxy_set_header X-Forwarded-Proto https;
  62. proxy_set_header Proxy "";
  63. proxy_pass_header Server;
  64. proxy_pass http://backend;
  65. proxy_buffering on;
  66. proxy_redirect off;
  67. proxy_http_version 1.1;
  68. proxy_set_header Upgrade $http_upgrade;
  69. proxy_set_header Connection $connection_upgrade;
  70. proxy_cache CACHE;
  71. proxy_cache_valid 200 7d;
  72. proxy_cache_valid 410 24h;
  73. proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  74. add_header X-Cached $upstream_cache_status;
  75. add_header Strict-Transport-Security "max-age=31536000";
  76. tcp_nodelay on;
  77. }
  78. location /api/v1/streaming {
  79. proxy_set_header Host $host;
  80. proxy_set_header X-Real-IP $remote_addr;
  81. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  82. proxy_set_header X-Forwarded-Proto https;
  83. proxy_set_header Proxy "";
  84. proxy_pass http://streaming;
  85. proxy_buffering off;
  86. proxy_redirect off;
  87. proxy_http_version 1.1;
  88. proxy_set_header Upgrade $http_upgrade;
  89. proxy_set_header Connection $connection_upgrade;
  90. tcp_nodelay on;
  91. }
  92. error_page 500 501 502 503 504 /500.html;
  93. }