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