peertube 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. server {
  2. listen 80;
  3. listen [::]:80;
  4. server_name peertube.example.com;
  5. access_log /var/log/nginx/peertube.example.com.access.log;
  6. error_log /var/log/nginx/peertube.example.com.error.log;
  7. location /.well-known/acme-challenge/ {
  8. default_type "text/plain";
  9. root /var/www/certbot;
  10. }
  11. location / { return 301 https://$host$request_uri; }
  12. }
  13. server {
  14. listen 443 ssl http2;
  15. listen [::]:443 ssl http2;
  16. server_name peertube.example.com;
  17. # For example with certbot (you need a certificate to run https)
  18. ssl_certificate /etc/letsencrypt/live/peertube.example.com/fullchain.pem;
  19. ssl_certificate_key /etc/letsencrypt/live/peertube.example.com/privkey.pem;
  20. # Security hardening (as of 11/02/2018)
  21. ssl_protocols TLSv1.2; # TLSv1.3, TLSv1.2 if nginx >= 1.13.0
  22. ssl_prefer_server_ciphers on;
  23. # Remove ECDHE-RSA-AES256-SHA if you don't want compatibility with Android 4
  24. ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA';
  25. # ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0, not compatible with import-videos script
  26. ssl_session_timeout 10m;
  27. ssl_session_cache shared:SSL:10m;
  28. ssl_session_tickets off; # Requires nginx >= 1.5.9
  29. ssl_stapling on; # Requires nginx >= 1.3.7
  30. ssl_stapling_verify on; # Requires nginx => 1.3.7
  31. # Configure with your resolvers
  32. # resolver $DNS-IP-1 $DNS-IP-2 valid=300s;
  33. # resolver_timeout 5s;
  34. # Enable compression for JS/CSS/HTML bundle, for improved client load times.
  35. # It might be nice to compress JSON, but leaving that out to protect against potential
  36. # compression+encryption information leak attacks like BREACH.
  37. gzip on;
  38. gzip_types text/css application/javascript;
  39. gzip_vary on;
  40. # If you have a small /var/lib partition, it could be interesting to store temp nginx uploads in a different place
  41. # See https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_temp_path
  42. # client_body_temp_path /var/www/peertube/storage/nginx/;
  43. # Enable HSTS
  44. # Tells browsers to stick with HTTPS and never visit the insecure HTTP
  45. # version. Once a browser sees this header, it will only visit the site over
  46. # HTTPS for the next 2 years: (read more on hstspreload.org)
  47. #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  48. access_log /var/log/nginx/peertube.example.com.access.log;
  49. error_log /var/log/nginx/peertube.example.com.error.log;
  50. location ^~ '/.well-known/acme-challenge' {
  51. default_type "text/plain";
  52. root /var/www/certbot;
  53. }
  54. # Bypass PeerTube for performance reasons. Could be removed
  55. location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ {
  56. add_header Cache-Control "public, max-age=31536000, immutable";
  57. alias /var/www/peertube/peertube-latest/client/dist/$1;
  58. }
  59. # Bypass PeerTube for performance reasons. Could be removed
  60. location ~ ^/static/(thumbnails|avatars)/ {
  61. if ($request_method = 'OPTIONS') {
  62. add_header 'Access-Control-Allow-Origin' '*';
  63. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  64. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  65. add_header 'Access-Control-Max-Age' 1728000;
  66. add_header 'Content-Type' 'text/plain charset=UTF-8';
  67. add_header 'Content-Length' 0;
  68. return 204;
  69. }
  70. add_header 'Access-Control-Allow-Origin' '*';
  71. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  72. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  73. # Cache 2 hours
  74. add_header Cache-Control "public, max-age=7200";
  75. root /var/www/peertube/storage;
  76. rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break;
  77. try_files $uri /;
  78. }
  79. location / {
  80. proxy_pass http://127.0.0.1:9000;
  81. proxy_set_header X-Real-IP $remote_addr;
  82. proxy_set_header Host $host;
  83. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  84. # This is the maximum upload size, which roughly matches the maximum size of a video file
  85. # you can send via the API or the web interface. By default this is 8GB, but administrators
  86. # can increase or decrease the limit. Currently there's no way to communicate this limit
  87. # to users automatically, so you may want to leave a note in your instance 'about' page if
  88. # you change this.
  89. #
  90. # Note that temporary space is needed equal to the total size of all concurrent uploads.
  91. # This data gets stored in /var/lib/nginx by default, so you may want to put this directory
  92. # on a dedicated filesystem.
  93. #
  94. client_max_body_size 8G;
  95. proxy_connect_timeout 600;
  96. proxy_send_timeout 600;
  97. proxy_read_timeout 600;
  98. send_timeout 600;
  99. }
  100. # Bypass PeerTube for performance reasons. Could be removed
  101. location ~ ^/static/(webseed|redundancy|streaming-playlists)/ {
  102. # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
  103. set $peertube_limit_rate 800k;
  104. # Increase rate limit in HLS mode, because we don't have multiple simultaneous connections
  105. if ($request_uri ~ -fragmented.mp4$) {
  106. set $peertube_limit_rate 5000k;
  107. }
  108. # Use this with nginx >= 1.17.0
  109. # limit_rate $peertube_limit_rate;
  110. # Or this if your nginx < 1.17.0
  111. set $limit_rate $peertube_limit_rate;
  112. limit_rate_after 5000k;
  113. if ($request_method = 'OPTIONS') {
  114. add_header 'Access-Control-Allow-Origin' '*';
  115. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  116. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  117. add_header 'Access-Control-Max-Age' 1728000;
  118. add_header 'Content-Type' 'text/plain charset=UTF-8';
  119. add_header 'Content-Length' 0;
  120. return 204;
  121. }
  122. if ($request_method = 'GET') {
  123. add_header 'Access-Control-Allow-Origin' '*';
  124. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  125. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  126. # Don't spam access log file with byte range requests
  127. access_log off;
  128. }
  129. root /var/www/peertube/storage;
  130. rewrite ^/static/webseed/(.*)$ /videos/$1 break;
  131. rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break;
  132. rewrite ^/static/streaming-playlists/(.*)$ /streaming-playlists/$1 break;
  133. try_files $uri /;
  134. }
  135. # Websocket tracker
  136. location /tracker/socket {
  137. # Peers send a message to the tracker every 15 minutes
  138. # Don't close the websocket before this time
  139. proxy_read_timeout 1200s;
  140. proxy_set_header Upgrade $http_upgrade;
  141. proxy_set_header Connection "upgrade";
  142. proxy_http_version 1.1;
  143. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  144. proxy_set_header Host $host;
  145. proxy_pass http://127.0.0.1:9000;
  146. }
  147. location /socket.io {
  148. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  149. proxy_set_header Host $host;
  150. proxy_pass http://127.0.0.1:9000;
  151. # enable WebSockets
  152. proxy_http_version 1.1;
  153. proxy_set_header Upgrade $http_upgrade;
  154. proxy_set_header Connection "upgrade";
  155. }
  156. }