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