From 0c4a90b78d67213e56e62c79e5b49d1b2157f247 Mon Sep 17 00:00:00 2001 From: mirsal Date: Sun, 21 Mar 2021 15:45:52 +0000 Subject: [PATCH] Add config options for choosing a webseed backend Send webseed data from the peertube_data docker volume using sendfile by default The proxy and CDN backends require that videos are uploaded to the backend (through fuse mounting for example) --- .env.sample | 17 +++++++++++++++++ nginx.conf.tmpl | 23 ++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.env.sample b/.env.sample index 32fc78c..b0cf3ad 100644 --- a/.env.sample +++ b/.env.sample @@ -11,6 +11,23 @@ PEERTUBE_ADMIN_EMAIL=admin@example.com PEERTUBE_SIGNUP_ENABLED=false PEERTUBE_TRANSCODING_ENABLED=true +## Webseed backend +# +# If no NGINX_WEBSEED option is enabled, videos will be served +# via sendfile, from the the app_data docker volume. + +# If the proxy backend is enabled, nginx will proxy requests to +# NGINX_WEBSEED_PROXY_URI and cache video data locally +# +#NGINX_WEBSEED_PROXY_ENABLE=true +#NGINX_WEBSEED_PROXY_URI=https://some-bucket.s3.api-endpoint.net + +# If the CDN backend is enabled, nginx will respond to webseed requests +# with redirects to NGINX_WEBSEED_CDN_URI instead of sending video data +# +#NGINX_WEBSEED_CDN_ENABLE=true +#NGINX_WEBSEED_CDN_URI=https://some-bucket.some-cdn.net + ## E-mail settings #PEERTUBE_SMTP_HOSTNAME=postfix_relay_app #PEERTUBE_SMTP_PORT=25 diff --git a/nginx.conf.tmpl b/nginx.conf.tmpl index acbf15f..657db2f 100644 --- a/nginx.conf.tmpl +++ b/nginx.conf.tmpl @@ -195,12 +195,15 @@ server { access_log off; } + aio threads; + # Enabling the sendfile directive eliminates the step of copying the data into the buffer # and enables direct copying data from one file descriptor to another. sendfile on; - sendfile_max_chunk 1M; # prevent one fast connection from entirely occupying the worker process. should be > 800k. - aio threads; + sendfile_max_chunk 1M; # prevent one fast connection from entirely occupying the worker process. + # should be > 800k. +{{ if (env "NGINX_WEBSEED_PROXY_ENABLE") }} proxy_connect_timeout 70; proxy_read_timeout 1200; proxy_send_timeout 1200; @@ -218,17 +221,23 @@ server { proxy_http_version 1.1; proxy_redirect off; + proxy_pass {{ env "NGINX_WEBSEED_PROXY_URI" }}; +{{ else }} + {{ if (env "NGINX_WEBSEED_CDN_ENABLE") }} # Use this in tandem with fuse-mounting i.e. https://docs.joinpeertube.org/admin-remote-storage # to serve files directly from a public bucket without proxying. # Assumes you have buckets named after the storage subdirectories, i.e. 'videos', 'redundancy', etc. - #set $cdn https://bucket-name.cdn.cloud; - #rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect; - #rewrite ^/static/(.*)$ $cdn/$1 redirect; + set $cdn {{ env "NGINX_WEBSEED_CDN_URI" }}; + rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect; + rewrite ^/static/(.*)$ $cdn/$1 redirect; + + {{ else }} rewrite ^/static/webseed/(.*)$ /videos/$1 break; rewrite ^/static/(.*)$ /$1 break; - try_files $uri @api; - #proxy_pass https://bucket-name.s3.api-endpoint.cloud; + {{ end }} + +{{ end }} } }