peertube 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. # HSTS (https://hstspreload.org), requires to be copied in 'location' sections that have add_header directives
  32. #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
  33. # Configure with your resolvers
  34. # resolver $DNS-IP-1 $DNS-IP-2 valid=300s;
  35. # resolver_timeout 5s;
  36. # Enable compression for JS/CSS/HTML bundle, for improved client load times.
  37. # It might be nice to compress JSON, but leaving that out to protect against potential
  38. # compression+encryption information leak attacks like BREACH.
  39. gzip on;
  40. gzip_types text/css application/javascript;
  41. gzip_vary on;
  42. # If you have a small /var/lib partition, it could be interesting to store temp nginx uploads in a different place
  43. # See https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_temp_path
  44. # client_body_temp_path /var/www/peertube/storage/nginx/;
  45. access_log /var/log/nginx/peertube.example.com.access.log;
  46. error_log /var/log/nginx/peertube.example.com.error.log;
  47. location ^~ '/.well-known/acme-challenge' {
  48. default_type "text/plain";
  49. root /var/www/certbot;
  50. }
  51. # Bypass PeerTube for performance reasons. Could be removed
  52. location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ {
  53. add_header Cache-Control "public, max-age=31536000, immutable";
  54. alias /var/www/peertube/peertube-latest/client/dist/$1;
  55. }
  56. # Bypass PeerTube for performance reasons. Could be removed
  57. location ~ ^/static/(thumbnails|avatars)/ {
  58. if ($request_method = 'OPTIONS') {
  59. add_header 'Access-Control-Allow-Origin' '*';
  60. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  61. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  62. add_header 'Access-Control-Max-Age' 1728000;
  63. add_header 'Content-Type' 'text/plain charset=UTF-8';
  64. add_header 'Content-Length' 0;
  65. return 204;
  66. }
  67. add_header 'Access-Control-Allow-Origin' '*';
  68. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  69. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  70. # Cache 2 hours
  71. add_header Cache-Control "public, max-age=7200";
  72. root /var/www/peertube/storage;
  73. rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break;
  74. try_files $uri /;
  75. }
  76. location / {
  77. proxy_pass http://127.0.0.1:9000;
  78. proxy_set_header X-Real-IP $remote_addr;
  79. proxy_set_header Host $host;
  80. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  81. # This is the maximum upload size, which roughly matches the maximum size of a video file
  82. # you can send via the API or the web interface. By default this is 8GB, but administrators
  83. # can increase or decrease the limit. Currently there's no way to communicate this limit
  84. # to users automatically, so you may want to leave a note in your instance 'about' page if
  85. # you change this.
  86. #
  87. # Note that temporary space is needed equal to the total size of all concurrent uploads.
  88. # This data gets stored in /var/lib/nginx by default, so you may want to put this directory
  89. # on a dedicated filesystem.
  90. #
  91. client_max_body_size 8G;
  92. proxy_connect_timeout 600;
  93. proxy_send_timeout 600;
  94. proxy_read_timeout 600;
  95. send_timeout 600;
  96. }
  97. # Bypass PeerTube for performance reasons. Could be removed
  98. location ~ ^/static/(webseed|redundancy|streaming-playlists)/ {
  99. # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
  100. set $peertube_limit_rate 800k;
  101. # Increase rate limit in HLS mode, because we don't have multiple simultaneous connections
  102. if ($request_uri ~ -fragmented.mp4$) {
  103. set $peertube_limit_rate 5000k;
  104. }
  105. # Use this with nginx >= 1.17.0
  106. # limit_rate $peertube_limit_rate;
  107. # Or this if your nginx < 1.17.0
  108. set $limit_rate $peertube_limit_rate;
  109. limit_rate_after 5000k;
  110. if ($request_method = 'OPTIONS') {
  111. add_header 'Access-Control-Allow-Origin' '*';
  112. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  113. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  114. add_header 'Access-Control-Max-Age' 1728000;
  115. add_header 'Content-Type' 'text/plain charset=UTF-8';
  116. add_header 'Content-Length' 0;
  117. return 204;
  118. }
  119. if ($request_method = 'GET') {
  120. add_header 'Access-Control-Allow-Origin' '*';
  121. add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  122. add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  123. # Don't spam access log file with byte range requests
  124. access_log off;
  125. }
  126. root /var/www/peertube/storage;
  127. # Use this in tandem with fuse-mounting i.e. https://docs.joinpeertube.org/#/admin-remote-storage
  128. # to serve files directly from a public bucket without proxying.
  129. # Assumes you have buckets named after the storage subdirectories, i.e. 'videos', 'redundancy', etc.
  130. #set $cdn <your S3-compatiable bucket public url mounted via fuse>;
  131. #rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect;
  132. #rewrite ^/static/redundancy/(.*)$ $cdn/redundancy/$1 redirect;
  133. #rewrite ^/static/streaming-playlists/(.*)$ $cdn/streaming-playlists/$1 redirect;
  134. rewrite ^/static/webseed/(.*)$ /videos/$1 break;
  135. rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break;
  136. rewrite ^/static/streaming-playlists/(.*)$ /streaming-playlists/$1 break;
  137. try_files $uri /;
  138. }
  139. # Websocket tracker
  140. location /tracker/socket {
  141. # Peers send a message to the tracker every 15 minutes
  142. # Don't close the websocket before this time
  143. proxy_read_timeout 1200s;
  144. proxy_set_header Upgrade $http_upgrade;
  145. proxy_set_header Connection "upgrade";
  146. proxy_http_version 1.1;
  147. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  148. proxy_set_header Host $host;
  149. proxy_pass http://127.0.0.1:9000;
  150. }
  151. location /socket.io {
  152. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  153. proxy_set_header Host $host;
  154. proxy_pass http://127.0.0.1:9000;
  155. # enable WebSockets
  156. proxy_http_version 1.1;
  157. proxy_set_header Upgrade $http_upgrade;
  158. proxy_set_header Connection "upgrade";
  159. }
  160. }