1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/peertube_ynh.git synced 2024-09-03 19:56:29 +02:00
peertube_ynh/conf/nginx.conf

203 lines
7.3 KiB
Nginx Configuration File
Raw Normal View History

2020-06-01 03:40:44 +02:00
more_set_headers "X-Frame-Options : ALLOWALL";
2021-03-31 02:56:34 +02:00
##
# Application
##
2020-06-01 03:40:44 +02:00
2021-03-30 22:58:26 +02:00
location @api {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 100k; # default is 1M
proxy_connect_timeout 10m;
proxy_send_timeout 10m;
proxy_read_timeout 10m;
send_timeout 10m;
2021-03-31 02:56:34 +02:00
proxy_pass http://127.0.0.1:__PORT__;
2021-03-30 22:58:26 +02:00
}
location / {
try_files /dev/null @api;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
2023-12-31 10:35:13 +01:00
location ~ ^/api/v1/videos/(upload-resumable|([^/]+/source/replace-resumable))$ {
client_max_body_size 0;
proxy_request_buffering off;
try_files /dev/null @api;
}
2022-06-09 09:09:57 +02:00
location ~ ^/api/v1/videos/(upload|([^/]+/studio/edit))$ {
2021-03-30 22:58:26 +02:00
limit_except POST HEAD { deny all; }
# This is the maximum upload size, which roughly matches the maximum size of a video file.
# Note that temporary space is needed equal to the total size of all concurrent uploads.
# This data gets stored in /var/lib/nginx by default, so you may want to put this directory
# on a dedicated filesystem.
2023-12-29 18:51:24 +01:00
client_max_body_size 24G; # default is 1M
2021-08-19 23:08:07 +02:00
more_set_headers "X-File-Maximum-Size : 16G always"; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)
2021-03-30 22:58:26 +02:00
try_files /dev/null @api;
}
2023-08-04 01:54:47 +02:00
location ~ ^/api/v1/runners/jobs/[^/]+/(update|success)$ {
2023-12-27 17:20:37 +01:00
client_max_body_size 12G; # default is 1M
2023-08-04 01:54:47 +02:00
more_set_headers "X-File-Maximum-Size : 8G always"; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)
try_files /dev/null @api;
}
2021-03-30 22:58:26 +02:00
location ~ ^/api/v1/(videos|video-playlists|video-channels|users/me) {
2023-12-27 17:20:37 +01:00
client_max_body_size 6M; # default is 1M
more_set_headers "X-File-Maximum-Size : 4M always"; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)
2021-03-30 22:58:26 +02:00
try_files /dev/null @api;
}
##
# Websocket
##
location @api_websocket {
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
2021-03-31 02:56:34 +02:00
proxy_pass http://127.0.0.1:__PORT__;
2021-03-30 22:58:26 +02:00
}
location /socket.io {
try_files /dev/null @api_websocket;
}
location /tracker/socket {
# Peers send a message to the tracker every 15 minutes
# Don't close the websocket before then
proxy_read_timeout 15m; # default is 60s
try_files /dev/null @api_websocket;
}
2022-12-15 11:11:11 +01:00
# Plugin websocket routes
location ~ ^/plugins/[^/]+(/[^/]+)?/ws/ {
try_files /dev/null @api_websocket;
}
2021-03-30 22:58:26 +02:00
##
# Performance optimizations
# For extra performance please refer to https://github.com/denji/nginx-tuning
##
2023-12-29 18:15:15 +01:00
root __DATA_DIR__/storage/;
2023-12-30 16:58:25 +01:00
2023-12-31 10:35:13 +01:00
# Enable compression for JS/CSS/HTML, for improved client load times.
# It might be nice to compress JSON/XML as returned by the API, but
# leaving that out to protect against potential BREACH attack.
2021-03-30 22:58:26 +02:00
# gzip on;
gzip_vary on;
gzip_types # text/html is always compressed by HttpGzipModule
text/css
application/javascript
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_min_length 1000; # default is 20 bytes
gzip_buffers 16 8k;
gzip_comp_level 2; # default is 1
client_body_timeout 30s; # default is 60
client_header_timeout 10s; # default is 60
send_timeout 10s; # default is 60
keepalive_timeout 10s; # default is 75
# resolver_timeout 10s; # default is 30
reset_timedout_connection on;
proxy_ignore_client_abort on;
tcp_nopush on; # send headers in one piece
tcp_nodelay on; # don't buffer data sent, good for small data bursts in real time
# If you have a small /var/lib partition, it could be interesting to store temp nginx uploads in a different place
# See https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_temp_path
#client_body_temp_path /var/www/peertube/storage/nginx/;
# Bypass PeerTube for performance reasons. Optional.
# Should be consistent with client-overrides assets list in /server/controllers/client.ts
2022-06-09 09:09:57 +02:00
location ~ ^/client/(assets/images/(icons/icon-36x36\.png|icons/icon-48x48\.png|icons/icon-72x72\.png|icons/icon-96x96\.png|icons/icon-144x144\.png|icons/icon-192x192\.png|icons/icon-512x512\.png|logo\.svg|favicon\.png|default-playlist\.jpg|default-avatar-account\.png|default-avatar-account-48x48\.png|default-avatar-video-channel\.png|default-avatar-video-channel-48x48\.png))$ {
2021-03-31 02:56:34 +02:00
more_set_headers "Cache-Control : public, max-age=31536000, immutable"; # Cache 1 year
2021-03-30 22:58:26 +02:00
2023-12-29 18:15:15 +01:00
try_files __DATA_DIR__/storage/client-overrides/$1 __INSTALL_DIR__/client/dist/$1 @api;
2021-03-30 22:58:26 +02:00
}
# Bypass PeerTube for performance reasons. Optional.
2020-06-02 14:57:05 +02:00
location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ {
2021-03-30 22:58:26 +02:00
more_set_headers "Cache-Control : public, max-age=31536000, immutable"; # Cache 1 year
2023-03-21 23:12:02 +01:00
alias __INSTALL_DIR__/client/dist/$1;
2020-02-23 19:42:08 +01:00
}
2024-01-18 18:42:37 +01:00
location ~ ^(/static/(webseed|web-videos|streaming-playlists/hls)/private/)|^/download {
2022-12-15 11:11:11 +01:00
# We can't rate limit a try_files directive, so we need to duplicate @api
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_limit_rate 5M;
proxy_pass http://127.0.0.1:__PORT__;
}
2021-03-30 22:58:26 +02:00
# Bypass PeerTube for performance reasons. Optional.
2023-12-31 09:19:27 +01:00
location ~ ^/static/(webseed|web-videos|redundancy|streaming-playlists)/ {
2021-03-30 22:58:26 +02:00
limit_rate_after 5M;
2023-08-04 01:54:47 +02:00
set $peertube_limit_rate 5M;
2020-06-02 14:57:05 +02:00
2021-03-30 22:58:26 +02:00
# Use this line with nginx >= 1.17.0
2022-12-15 11:11:11 +01:00
limit_rate $peertube_limit_rate;
2023-08-04 01:54:47 +02:00
# Or this line with nginx < 1.17.0
2022-12-15 11:11:11 +01:00
# set $limit_rate $peertube_limit_rate;
2017-12-08 00:35:52 +01:00
2020-02-23 19:42:08 +01:00
if ($request_method = 'OPTIONS') {
2020-06-02 15:02:33 +02:00
more_set_headers "Access-Control-Allow-Origin : *";
more_set_headers "Access-Control-Allow-Methods : GET, OPTIONS";
more_set_headers "Access-Control-Allow-Headers : Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type";
2021-03-30 22:58:26 +02:00
more_set_headers "Access-Control-Max-Age : 1728000"; # Preflight request can be cached 20 days
2020-06-02 15:02:33 +02:00
more_set_headers "Content-Type : text/plain charset=UTF-8";
more_set_headers "Content-Length : 0";
2020-02-23 19:42:08 +01:00
return 204;
2017-12-08 00:35:52 +01:00
}
2020-02-23 19:42:08 +01:00
if ($request_method = 'GET') {
2020-06-02 15:02:33 +02:00
more_set_headers "Access-Control-Allow-Origin : *";
more_set_headers "Access-Control-Allow-Methods : GET, OPTIONS";
more_set_headers "Access-Control-Allow-Headers : Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type";
2020-02-23 19:42:08 +01:00
# Don't spam access log file with byte range requests
access_log off;
2017-12-08 00:35:52 +01:00
}
2019-02-07 20:18:54 +01:00
2021-03-30 22:58:26 +02:00
# 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;
2023-08-04 01:54:47 +02:00
# web-videos is the name of the directory mapped to the `storage.web_videos` key in your PeerTube configuration
2023-12-31 09:19:27 +01:00
rewrite ^/static/webseed/(.*)$ /web-videos/$1 break;
2021-03-30 22:58:26 +02:00
rewrite ^/static/(.*)$ /$1 break;
2019-02-07 20:30:42 +01:00
2023-12-29 18:15:15 +01:00
root __DATA_DIR__/storage/;
2019-02-07 20:30:42 +01:00
2021-03-30 22:58:26 +02:00
try_files $uri @api;
2020-02-23 19:42:08 +01:00
}