1 # Minimum Nginx version required: 1.13.0 (released Apr 25, 2017)
2 # Please check your Nginx installation features the following modules via 'nginx -V':
3 # STANDARD HTTP MODULES: Core, Proxy, Rewrite, Access, Gzip, Headers, HTTP/2, Log, Real IP, SSL, Thread Pool, Upstream, AIO Multithreading.
4 # THIRD PARTY MODULES: None.
9 server_name ${WEBSERVER_HOST};
11 location /.well-known/acme-challenge/ {
12 default_type "text/plain";
13 root /var/www/certbot;
15 location / { return 301 https://$host$request_uri; }
19 server ${PEERTUBE_HOST};
24 listen [::]:443 ssl http2;
25 server_name ${WEBSERVER_HOST};
27 access_log /var/log/nginx/peertube.access.log; # reduce I/0 with buffer=10m flush=5m
28 error_log /var/log/nginx/peertube.error.log;
32 # you need a certificate to run in production. see https://letsencrypt.org/
34 ssl_certificate /etc/letsencrypt/live/${WEBSERVER_HOST}/fullchain.pem;
35 ssl_certificate_key /etc/letsencrypt/live/${WEBSERVER_HOST}/privkey.pem;
37 location ^~ '/.well-known/acme-challenge' {
38 default_type "text/plain";
39 root /var/www/certbot;
43 # Security hardening (as of Nov 15, 2020)
44 # based on Mozilla Guideline v5.6
47 ssl_protocols TLSv1.2 TLSv1.3;
48 ssl_prefer_server_ciphers on;
49 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; # add ECDHE-RSA-AES256-SHA if you want compatibility with Android 4
50 ssl_session_timeout 1d; # defaults to 5m
51 ssl_session_cache shared:SSL:10m; # estimated to 40k sessions
52 ssl_session_tickets off;
54 ssl_stapling_verify on;
55 # HSTS (https://hstspreload.org), requires to be copied in 'location' sections that have add_header directives
56 #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
63 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
64 proxy_set_header Host $host;
65 proxy_set_header X-Real-IP $remote_addr;
67 client_max_body_size 100k; # default is 1M
69 proxy_connect_timeout 10m;
70 proxy_send_timeout 10m;
71 proxy_read_timeout 10m;
74 proxy_pass http://backend;
78 try_files /dev/null @api;
81 location = /api/v1/videos/upload-resumable {
82 client_max_body_size 0;
83 proxy_request_buffering off;
85 try_files /dev/null @api;
88 location ~ ^/api/v1/videos/(upload|([^/]+/studio/edit))$ {
89 limit_except POST HEAD { deny all; }
91 # This is the maximum upload size, which roughly matches the maximum size of a video file.
92 # Note that temporary space is needed equal to the total size of all concurrent uploads.
93 # This data gets stored in /var/lib/nginx by default, so you may want to put this directory
94 # on a dedicated filesystem.
95 client_max_body_size 12G; # default is 1M
96 add_header X-File-Maximum-Size 8G always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)
98 try_files /dev/null @api;
101 location ~ ^/api/v1/runners/jobs/[^/]+/(update|success)$ {
102 client_max_body_size 12G; # default is 1M
103 add_header X-File-Maximum-Size 8G always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)
105 try_files /dev/null @api;
108 location ~ ^/api/v1/(videos|video-playlists|video-channels|users/me) {
109 client_max_body_size 6M; # default is 1M
110 add_header X-File-Maximum-Size 4M always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size)
112 try_files /dev/null @api;
119 location @api_websocket {
120 proxy_http_version 1.1;
121 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
122 proxy_set_header Host $host;
123 proxy_set_header X-Real-IP $remote_addr;
124 proxy_set_header Upgrade $http_upgrade;
125 proxy_set_header Connection "upgrade";
127 proxy_pass http://backend;
130 location /socket.io {
131 try_files /dev/null @api_websocket;
134 location /tracker/socket {
135 # Peers send a message to the tracker every 15 minutes
136 # Don't close the websocket before then
137 proxy_read_timeout 15m; # default is 60s
139 try_files /dev/null @api_websocket;
142 # Plugin websocket routes
143 location ~ ^/plugins/[^/]+(/[^/]+)?/ws/ {
144 try_files /dev/null @api_websocket;
148 # Performance optimizations
149 # For extra performance please refer to https://github.com/denji/nginx-tuning
152 root /var/www/peertube/storage;
154 # Enable compression for JS/CSS/HTML, for improved client load times.
155 # It might be nice to compress JSON/XML as returned by the API, but
156 # leaving that out to protect against potential BREACH attack.
159 gzip_types # text/html is always compressed by HttpGzipModule
161 application/javascript
164 application/vnd.ms-fontobject
166 gzip_min_length 1000; # default is 20 bytes
168 gzip_comp_level 2; # default is 1
170 client_body_timeout 30s; # default is 60
171 client_header_timeout 10s; # default is 60
172 send_timeout 10s; # default is 60
173 keepalive_timeout 10s; # default is 75
174 resolver_timeout 10s; # default is 30
175 reset_timedout_connection on;
176 proxy_ignore_client_abort on;
178 tcp_nopush on; # send headers in one piece
179 tcp_nodelay on; # don't buffer data sent, good for small data bursts in real time
181 # If you have a small /var/lib partition, it could be interesting to store temp nginx uploads in a different place
182 # See https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_temp_path
183 #client_body_temp_path /var/www/peertube/storage/nginx/;
185 # Bypass PeerTube for performance reasons. Optional.
186 # Should be consistent with client-overrides assets list in /server/controllers/client.ts
187 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))$ {
188 add_header Cache-Control "public, max-age=31536000, immutable"; # Cache 1 year
190 root /var/www/peertube;
192 try_files /storage/client-overrides/$1 /peertube-latest/client/dist/$1 @api;
195 # Bypass PeerTube for performance reasons. Optional.
196 location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ {
197 add_header Cache-Control "public, max-age=31536000, immutable"; # Cache 1 year
199 alias /var/www/peertube/peertube-latest/client/dist/$1;
202 # Bypass PeerTube for performance reasons. Optional.
203 location ~ ^/static/(thumbnails|avatars)/ {
204 if ($request_method = 'OPTIONS') {
205 add_header Access-Control-Allow-Origin '*';
206 add_header Access-Control-Allow-Methods 'GET, OPTIONS';
207 add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
208 add_header Access-Control-Max-Age 1728000; # Preflight request can be cached 20 days
209 add_header Content-Type 'text/plain charset=UTF-8';
210 add_header Content-Length 0;
214 add_header Access-Control-Allow-Origin '*';
215 add_header Access-Control-Allow-Methods 'GET, OPTIONS';
216 add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
217 add_header Cache-Control "public, max-age=7200"; # Cache response 2 hours
219 rewrite ^/static/(.*)$ /$1 break;
224 location ~ ^(/static/(webseed|streaming-playlists)/private/)|^/download {
225 # We can't rate limit a try_files directive, so we need to duplicate @api
227 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
228 proxy_set_header Host $host;
229 proxy_set_header X-Real-IP $remote_addr;
233 proxy_pass http://backend;
236 # Bypass PeerTube for performance reasons. Optional.
237 location ~ ^/static/(webseed|redundancy|streaming-playlists)/ {
240 # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
241 set $peertube_limit_rate 800k;
243 # Increase rate limit in HLS mode, because we don't have multiple simultaneous connections
244 if ($request_uri ~ -fragmented.mp4$) {
245 set $peertube_limit_rate 5M;
248 # Use this line with nginx >= 1.17.0
249 limit_rate $peertube_limit_rate;
250 # Or this line with nginx < 1.17.0
251 # set $limit_rate $peertube_limit_rate;
253 if ($request_method = 'OPTIONS') {
254 add_header Access-Control-Allow-Origin '*';
255 add_header Access-Control-Allow-Methods 'GET, OPTIONS';
256 add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
257 add_header Access-Control-Max-Age 1728000; # Preflight request can be cached 20 days
258 add_header Content-Type 'text/plain charset=UTF-8';
259 add_header Content-Length 0;
263 if ($request_method = 'GET') {
264 add_header Access-Control-Allow-Origin '*';
265 add_header Access-Control-Allow-Methods 'GET, OPTIONS';
266 add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
268 # Don't spam access log file with byte range requests
272 # Enabling the sendfile directive eliminates the step of copying the data into the buffer
273 # and enables direct copying data from one file descriptor to another.
275 sendfile_max_chunk 1M; # prevent one fast connection from entirely occupying the worker process. should be > 800k.
278 rewrite ^/static/webseed/(.*)$ /videos/$1 break;
279 rewrite ^/static/(.*)$ /$1 break;