From 53c23727e7659802644b578dab33bb8240c5262e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 10 Jul 2019 23:56:26 +0200 Subject: [PATCH] Serve video files directly from disk --- templates/docker-compose.yml | 1 + templates/nginx.conf | 49 +++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/templates/docker-compose.yml b/templates/docker-compose.yml index 02983a8..fe11465 100644 --- a/templates/docker-compose.yml +++ b/templates/docker-compose.yml @@ -27,6 +27,7 @@ services: image: nginx:1.15-alpine volumes: - ./nginx.conf:/etc/nginx/nginx.conf + - ./volumes-large:/data-external:ro labels: - traefik.enable=true - traefik.frontend.rule=Host:${PEERTUBE_WEBSERVER_HOSTNAME} diff --git a/templates/nginx.conf b/templates/nginx.conf index c82f3d1..f71e843 100644 --- a/templates/nginx.conf +++ b/templates/nginx.conf @@ -47,17 +47,48 @@ http { add_header X-Cached $upstream_cache_status; } location ~ ^/static/(webseed|redundancy)/ { - slice 1m; - proxy_cache peertube_cache; - proxy_cache_valid 206 1h; - proxy_cache_key $uri$is_args$args$slice_range; - proxy_set_header Range $slice_range; + # NOTE: Its not possible to use proxy_cache for files that are served from disk without complicated workarounds + # Anyway caching is not a great idea because files are changed on disk after transcoding. + #slice 1m; + #proxy_cache peertube_cache; + #proxy_cache_valid 206 1h; + #proxy_cache_key $uri$is_args$args$slice_range; + #proxy_set_header Range $slice_range; + #proxy_http_version 1.1; + #proxy_pass http://peertube:9000; + # required workaround for https://github.com/Chocobozzz/PeerTube/issues/1777 + #proxy_ignore_headers Cache-Control; # for debugging #add_header X-Cache-Status $upstream_cache_status; - proxy_http_version 1.1; - # required workaround for https://github.com/Chocobozzz/PeerTube/issues/1777 - proxy_ignore_headers Cache-Control; - proxy_pass http://peertube:9000; + + # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client + limit_rate 800k; + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + + # Don't spam access log file with byte range requests + access_log off; + } + + root /data-external; + + rewrite ^/static/webseed/(.*)$ /videos/$1 break; + rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break; + + try_files $uri /; } } }