]>
Commit | Line | Data |
---|---|---|
5f59cf07 | 1 | # Minimum Nginx version required: 1.13.0 (released Apr 25, 2017) |
11c449eb | 2 | # Please check your Nginx installation features the following modules via 'nginx -V': |
dbe3040e | 3 | # STANDARD HTTP MODULES: Core, Proxy, Rewrite, Access, Gzip, Headers, HTTP/2, Log, Real IP, SSL, Thread Pool, Upstream, AIO Multithreading. |
11c449eb | 4 | # THIRD PARTY MODULES: None. |
5f59cf07 | 5 | |
afd4ee86 C |
6 | server { |
7 | listen 80; | |
8 | listen [::]:80; | |
9 | server_name ${WEBSERVER_HOST}; | |
10 | ||
11 | location /.well-known/acme-challenge/ { | |
12 | default_type "text/plain"; | |
13 | root /var/www/certbot; | |
14 | } | |
15 | location / { return 301 https://$host$request_uri; } | |
16 | } | |
c97eea23 | 17 | |
5f59cf07 RK |
18 | upstream backend { |
19 | server ${PEERTUBE_HOST}; | |
20 | } | |
21 | ||
c97eea23 | 22 | server { |
85cd9bde | 23 | listen 443 ssl http2; |
e883399f | 24 | listen [::]:443 ssl http2; |
1a9b141d | 25 | server_name ${WEBSERVER_HOST}; |
c97eea23 | 26 | |
5f59cf07 RK |
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; | |
29 | ||
30 | ## | |
31 | # Certificates | |
32 | # you need a certificate to run in production. see https://letsencrypt.org/ | |
33 | ## | |
afd4ee86 C |
34 | ssl_certificate /etc/letsencrypt/live/${WEBSERVER_HOST}/fullchain.pem; |
35 | ssl_certificate_key /etc/letsencrypt/live/${WEBSERVER_HOST}/privkey.pem; | |
5f59cf07 RK |
36 | |
37 | location ^~ '/.well-known/acme-challenge' { | |
38 | default_type "text/plain"; | |
39 | root /var/www/certbot; | |
40 | } | |
41 | ||
42 | ## | |
43 | # Security hardening (as of Nov 15, 2020) | |
44 | # based on Mozilla Guideline v5.6 | |
45 | ## | |
0b495712 | 46 | |
5f59cf07 | 47 | ssl_protocols TLSv1.2 TLSv1.3; |
e883399f | 48 | ssl_prefer_server_ciphers on; |
5f59cf07 RK |
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; | |
53 | ssl_stapling on; | |
54 | ssl_stapling_verify on; | |
62df8cc1 RK |
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"; | |
0b495712 | 57 | |
5f59cf07 RK |
58 | ## |
59 | # Application | |
60 | ## | |
0b495712 | 61 | |
b2aecc1e | 62 | location @api { |
d4132d3f RK |
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; | |
b9ad9956 | 66 | |
b2aecc1e RK |
67 | client_max_body_size 100k; # default is 1M |
68 | ||
69 | proxy_connect_timeout 10m; | |
70 | proxy_send_timeout 10m; | |
71 | proxy_read_timeout 10m; | |
72 | send_timeout 10m; | |
73 | ||
74 | proxy_pass http://backend; | |
75 | } | |
76 | ||
77 | location / { | |
78 | try_files /dev/null @api; | |
79 | } | |
80 | ||
f6d6e7f8 | 81 | location = /api/v1/videos/upload-resumable { |
f2b5aa59 C |
82 | if ($request_method = 'PUT') { |
83 | client_max_body_size 0; | |
84 | proxy_request_buffering off; | |
85 | } | |
f6d6e7f8 | 86 | |
87 | try_files /dev/null @api; | |
88 | } | |
89 | ||
b2aecc1e | 90 | location = /api/v1/videos/upload { |
d4132d3f RK |
91 | limit_except POST HEAD { deny all; } |
92 | ||
93 | # This is the maximum upload size, which roughly matches the maximum size of a video file. | |
5f59cf07 RK |
94 | # Note that temporary space is needed equal to the total size of all concurrent uploads. |
95 | # This data gets stored in /var/lib/nginx by default, so you may want to put this directory | |
96 | # on a dedicated filesystem. | |
e0114655 RK |
97 | client_max_body_size 12G; # default is 1M |
98 | 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) | |
5668bf2e | 99 | |
b2aecc1e | 100 | try_files /dev/null @api; |
5f59cf07 RK |
101 | } |
102 | ||
6c7317a0 C |
103 | location ~ ^/api/v1/(videos|video-playlists|video-channels|users/me) { |
104 | client_max_body_size 3M; # default is 1M | |
105 | add_header X-File-Maximum-Size 2M always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size) | |
106 | ||
107 | try_files /dev/null @api; | |
108 | } | |
109 | ||
5f59cf07 RK |
110 | ## |
111 | # Websocket | |
112 | ## | |
113 | ||
b2aecc1e | 114 | location @api_websocket { |
5f59cf07 RK |
115 | proxy_http_version 1.1; |
116 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
117 | proxy_set_header Host $host; | |
118 | proxy_set_header X-Real-IP $remote_addr; | |
119 | proxy_set_header Upgrade $http_upgrade; | |
120 | proxy_set_header Connection "upgrade"; | |
121 | ||
5f59cf07 RK |
122 | proxy_pass http://backend; |
123 | } | |
124 | ||
125 | location /socket.io { | |
b2aecc1e RK |
126 | try_files /dev/null @api_websocket; |
127 | } | |
5f59cf07 | 128 | |
b2aecc1e RK |
129 | location /tracker/socket { |
130 | # Peers send a message to the tracker every 15 minutes | |
131 | # Don't close the websocket before then | |
132 | proxy_read_timeout 15m; # default is 60s | |
133 | ||
134 | try_files /dev/null @api_websocket; | |
e883399f | 135 | } |
c97eea23 | 136 | |
5f59cf07 RK |
137 | ## |
138 | # Performance optimizations | |
139 | # For extra performance please refer to https://github.com/denji/nginx-tuning | |
140 | ## | |
141 | ||
142 | root /var/www/peertube/storage; | |
143 | ||
144 | # Enable compression for JS/CSS/HTML, for improved client load times. | |
145 | # It might be nice to compress JSON/XML as returned by the API, but | |
146 | # leaving that out to protect against potential BREACH attack. | |
147 | gzip on; | |
148 | gzip_vary on; | |
149 | gzip_types # text/html is always compressed by HttpGzipModule | |
150 | text/css | |
151 | application/javascript | |
152 | font/truetype | |
153 | font/opentype | |
154 | application/vnd.ms-fontobject | |
155 | image/svg+xml; | |
156 | gzip_min_length 1000; # default is 20 bytes | |
157 | gzip_buffers 16 8k; | |
158 | gzip_comp_level 2; # default is 1 | |
159 | ||
160 | client_body_timeout 30s; # default is 60 | |
161 | client_header_timeout 10s; # default is 60 | |
162 | send_timeout 10s; # default is 60 | |
163 | keepalive_timeout 10s; # default is 75 | |
164 | resolver_timeout 10s; # default is 30 | |
165 | reset_timedout_connection on; | |
df7b786f | 166 | proxy_ignore_client_abort on; |
5f59cf07 RK |
167 | |
168 | tcp_nopush on; # send headers in one piece | |
169 | tcp_nodelay on; # don't buffer data sent, good for small data bursts in real time | |
170 | ||
5f59cf07 RK |
171 | # If you have a small /var/lib partition, it could be interesting to store temp nginx uploads in a different place |
172 | # See https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_temp_path | |
173 | #client_body_temp_path /var/www/peertube/storage/nginx/; | |
174 | ||
b2aecc1e | 175 | # Bypass PeerTube for performance reasons. Optional. |
8872828d K |
176 | # Should be consistent with client-overrides assets list in /server/controllers/client.ts |
177 | 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))$ { | |
5f59cf07 | 178 | add_header Cache-Control "public, max-age=31536000, immutable"; # Cache 1 year |
8872828d | 179 | |
901c36d5 RK |
180 | root /var/www/peertube; |
181 | ||
b2aecc1e | 182 | try_files /storage/client-overrides/$1 /peertube-latest/client/dist/$1 @api; |
8872828d K |
183 | } |
184 | ||
5f59cf07 | 185 | # Bypass PeerTube for performance reasons. Optional. |
c928e136 | 186 | location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ { |
5f59cf07 | 187 | add_header Cache-Control "public, max-age=31536000, immutable"; # Cache 1 year |
5668bf2e | 188 | |
59c48d49 | 189 | alias /var/www/peertube/peertube-latest/client/dist/$1; |
5668bf2e C |
190 | } |
191 | ||
5f59cf07 | 192 | # Bypass PeerTube for performance reasons. Optional. |
a8bf1d82 | 193 | location ~ ^/static/(thumbnails|avatars)/ { |
7f8db30c | 194 | if ($request_method = 'OPTIONS') { |
b2aecc1e RK |
195 | add_header Access-Control-Allow-Origin '*'; |
196 | add_header Access-Control-Allow-Methods 'GET, OPTIONS'; | |
197 | add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
198 | add_header Access-Control-Max-Age 1728000; # Preflight request can be cached 20 days | |
199 | add_header Content-Type 'text/plain charset=UTF-8'; | |
200 | add_header Content-Length 0; | |
7f8db30c C |
201 | return 204; |
202 | } | |
203 | ||
b2aecc1e RK |
204 | add_header Access-Control-Allow-Origin '*'; |
205 | add_header Access-Control-Allow-Methods 'GET, OPTIONS'; | |
206 | add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
207 | add_header Cache-Control "public, max-age=7200"; # Cache response 2 hours | |
5668bf2e | 208 | |
5f59cf07 | 209 | rewrite ^/static/(.*)$ /$1 break; |
a8bf1d82 | 210 | |
b2aecc1e | 211 | try_files $uri @api; |
5668bf2e C |
212 | } |
213 | ||
5f59cf07 | 214 | # Bypass PeerTube for performance reasons. Optional. |
f37db896 | 215 | location ~ ^/static/(webseed|redundancy|streaming-playlists)/ { |
5f59cf07 RK |
216 | limit_rate_after 5M; |
217 | ||
63247475 | 218 | # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client |
5f59cf07 | 219 | set $peertube_limit_rate 800k; |
63247475 C |
220 | |
221 | # Increase rate limit in HLS mode, because we don't have multiple simultaneous connections | |
222 | if ($request_uri ~ -fragmented.mp4$) { | |
5f59cf07 | 223 | set $peertube_limit_rate 5M; |
63247475 C |
224 | } |
225 | ||
5f59cf07 RK |
226 | # Use this line with nginx >= 1.17.0 |
227 | #limit_rate $peertube_limit_rate; | |
228 | # Or this line if your nginx < 1.17.0 | |
63247475 | 229 | set $limit_rate $peertube_limit_rate; |
85cd9bde | 230 | |
c97eea23 | 231 | if ($request_method = 'OPTIONS') { |
b2aecc1e RK |
232 | add_header Access-Control-Allow-Origin '*'; |
233 | add_header Access-Control-Allow-Methods 'GET, OPTIONS'; | |
234 | add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
235 | add_header Access-Control-Max-Age 1728000; # Preflight request can be cached 20 days | |
236 | add_header Content-Type 'text/plain charset=UTF-8'; | |
237 | add_header Content-Length 0; | |
c97eea23 C |
238 | return 204; |
239 | } | |
240 | ||
241 | if ($request_method = 'GET') { | |
b2aecc1e RK |
242 | add_header Access-Control-Allow-Origin '*'; |
243 | add_header Access-Control-Allow-Methods 'GET, OPTIONS'; | |
244 | add_header Access-Control-Allow-Headers 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
5668bf2e C |
245 | |
246 | # Don't spam access log file with byte range requests | |
247 | access_log off; | |
c97eea23 C |
248 | } |
249 | ||
5f59cf07 RK |
250 | # Enabling the sendfile directive eliminates the step of copying the data into the buffer |
251 | # and enables direct copying data from one file descriptor to another. | |
252 | sendfile on; | |
253 | sendfile_max_chunk 1M; # prevent one fast connection from entirely occupying the worker process. should be > 800k. | |
254 | aio threads; | |
b9fffa29 | 255 | |
9817060f | 256 | # Use this in tandem with fuse-mounting i.e. https://docs.joinpeertube.org/admin-remote-storage |
61b20252 RK |
257 | # to serve files directly from a public bucket without proxying. |
258 | # Assumes you have buckets named after the storage subdirectories, i.e. 'videos', 'redundancy', etc. | |
259 | #set $cdn <your S3-compatiable bucket public url mounted via fuse>; | |
260 | #rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect; | |
5f59cf07 | 261 | #rewrite ^/static/(.*)$ $cdn/$1 redirect; |
b9fffa29 | 262 | rewrite ^/static/webseed/(.*)$ /videos/$1 break; |
5f59cf07 | 263 | rewrite ^/static/(.*)$ /$1 break; |
b9fffa29 | 264 | |
b2aecc1e | 265 | try_files $uri @api; |
c97eea23 | 266 | } |
c97eea23 | 267 | } |