]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/nginx/peertube
add client overrides to nginx configuration (#3297)
[github/Chocobozzz/PeerTube.git] / support / nginx / peertube
CommitLineData
1a9b141d
RK
1# Uncomment in production to redirect HTTP to HTTPS. Leave commented for docker-compose.
2#server {
3# listen 80;
4# listen [::]:80;
5# server_name ${WEBSERVER_HOST};
6#
7# location /.well-known/acme-challenge/ {
8# default_type "text/plain";
9# root /var/www/certbot;
10# }
11# location / { return 301 https://$host$request_uri; }
12#}
c97eea23
C
13
14server {
85cd9bde 15 listen 443 ssl http2;
e883399f 16 listen [::]:443 ssl http2;
1a9b141d 17 server_name ${WEBSERVER_HOST};
c97eea23 18
0b495712 19 # For example with certbot (you need a certificate to run https)
1a9b141d
RK
20 ssl_certificate /etc/letsencrypt/live/${WEBSERVER_HOST}/fullchain.pem;
21 ssl_certificate_key /etc/letsencrypt/live/${WEBSERVER_HOST}/privkey.pem;
0b495712 22
e883399f 23 # Security hardening (as of 11/02/2018)
0b495712 24 ssl_protocols TLSv1.2; # TLSv1.3, TLSv1.2 if nginx >= 1.13.0
e883399f 25 ssl_prefer_server_ciphers on;
1a5fd848
C
26 # Remove ECDHE-RSA-AES256-SHA if you don't want compatibility with Android 4
27 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:ECDHE-RSA-AES256-SHA';
4919b630 28 # ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0, not compatible with import-videos script
e883399f
RK
29 ssl_session_timeout 10m;
30 ssl_session_cache shared:SSL:10m;
31 ssl_session_tickets off; # Requires nginx >= 1.5.9
32 ssl_stapling on; # Requires nginx >= 1.3.7
33 ssl_stapling_verify on; # Requires nginx => 1.3.7
62df8cc1
RK
34 # HSTS (https://hstspreload.org), requires to be copied in 'location' sections that have add_header directives
35 #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
0b495712
C
36
37 # Configure with your resolvers
38 # resolver $DNS-IP-1 $DNS-IP-2 valid=300s;
39 # resolver_timeout 5s;
40
a18e02f3
MES
41 # Enable compression for JS/CSS/HTML bundle, for improved client load times.
42 # It might be nice to compress JSON, but leaving that out to protect against potential
43 # compression+encryption information leak attacks like BREACH.
b9ad9956 44 gzip on;
7eeb6a0b 45 gzip_types text/css application/javascript;
b9ad9956
MES
46 gzip_vary on;
47
7b7d4e2a
C
48 # If you have a small /var/lib partition, it could be interesting to store temp nginx uploads in a different place
49 # See https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_temp_path
50 # client_body_temp_path /var/www/peertube/storage/nginx/;
51
1a9b141d
RK
52 access_log /var/log/nginx/${WEBSERVER_HOST}.access.log;
53 error_log /var/log/nginx/${WEBSERVER_HOST}.error.log;
5668bf2e 54
e883399f
RK
55 location ^~ '/.well-known/acme-challenge' {
56 default_type "text/plain";
57 root /var/www/certbot;
58 }
c97eea23 59
8872828d
K
60 # Bypass PeerTube for performance reasons. Could be removed
61 # Should be consistent with client-overrides assets list in /server/controllers/client.ts
62 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))$ {
63 add_header Cache-Control "public, max-age=31536000, immutable";
64
65 root /var/www/peertube/storage/client-overrides;
66
67 try_files /$1 $uri;
68 }
69
415acc63 70 # Bypass PeerTube for performance reasons. Could be removed
c928e136 71 location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ {
5668bf2e
C
72 add_header Cache-Control "public, max-age=31536000, immutable";
73
59c48d49 74 alias /var/www/peertube/peertube-latest/client/dist/$1;
5668bf2e
C
75 }
76
415acc63 77 # Bypass PeerTube for performance reasons. Could be removed
a8bf1d82 78 location ~ ^/static/(thumbnails|avatars)/ {
7f8db30c
C
79 if ($request_method = 'OPTIONS') {
80 add_header 'Access-Control-Allow-Origin' '*';
81 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
82 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
83 add_header 'Access-Control-Max-Age' 1728000;
84 add_header 'Content-Type' 'text/plain charset=UTF-8';
85 add_header 'Content-Length' 0;
86 return 204;
87 }
88
a8bf1d82
C
89 add_header 'Access-Control-Allow-Origin' '*';
90 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
91 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
7f8db30c 92
57a81ff6
C
93 # Cache 2 hours
94 add_header Cache-Control "public, max-age=7200";
5668bf2e 95
a8bf1d82
C
96 root /var/www/peertube/storage;
97
98 rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break;
99 try_files $uri /;
5668bf2e
C
100 }
101
c97eea23 102 location / {
1a9b141d 103 proxy_pass http://${PEERTUBE_HOST};
c97eea23
C
104 proxy_set_header X-Real-IP $remote_addr;
105 proxy_set_header Host $host;
106 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
107
4b493858
MES
108 # This is the maximum upload size, which roughly matches the maximum size of a video file
109 # you can send via the API or the web interface. By default this is 8GB, but administrators
110 # can increase or decrease the limit. Currently there's no way to communicate this limit
111 # to users automatically, so you may want to leave a note in your instance 'about' page if
112 # you change this.
113 #
114 # Note that temporary space is needed equal to the total size of all concurrent uploads.
115 # This data gets stored in /var/lib/nginx by default, so you may want to put this directory
116 # on a dedicated filesystem.
117 #
34b19192 118 client_max_body_size 8G;
4b493858 119
7e9334c3
C
120 proxy_connect_timeout 600;
121 proxy_send_timeout 600;
122 proxy_read_timeout 600;
e883399f 123 send_timeout 600;
c97eea23
C
124 }
125
415acc63 126 # Bypass PeerTube for performance reasons. Could be removed
f37db896 127 location ~ ^/static/(webseed|redundancy|streaming-playlists)/ {
63247475
C
128 # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
129 set $peertube_limit_rate 800k;
130
131 # Increase rate limit in HLS mode, because we don't have multiple simultaneous connections
132 if ($request_uri ~ -fragmented.mp4$) {
133 set $peertube_limit_rate 5000k;
134 }
135
136 # Use this with nginx >= 1.17.0
137 # limit_rate $peertube_limit_rate;
138 # Or this if your nginx < 1.17.0
139 set $limit_rate $peertube_limit_rate;
140 limit_rate_after 5000k;
85cd9bde 141
c97eea23
C
142 if ($request_method = 'OPTIONS') {
143 add_header 'Access-Control-Allow-Origin' '*';
144 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
145 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
146 add_header 'Access-Control-Max-Age' 1728000;
147 add_header 'Content-Type' 'text/plain charset=UTF-8';
148 add_header 'Content-Length' 0;
149 return 204;
150 }
151
152 if ($request_method = 'GET') {
153 add_header 'Access-Control-Allow-Origin' '*';
154 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
155 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
156
157 # Don't spam access log file with byte range requests
158 access_log off;
c97eea23
C
159 }
160
b9fffa29
C
161 root /var/www/peertube/storage;
162
61b20252
RK
163 # Use this in tandem with fuse-mounting i.e. https://docs.joinpeertube.org/#/admin-remote-storage
164 # to serve files directly from a public bucket without proxying.
165 # Assumes you have buckets named after the storage subdirectories, i.e. 'videos', 'redundancy', etc.
166 #set $cdn <your S3-compatiable bucket public url mounted via fuse>;
167 #rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect;
168 #rewrite ^/static/redundancy/(.*)$ $cdn/redundancy/$1 redirect;
169 #rewrite ^/static/streaming-playlists/(.*)$ $cdn/streaming-playlists/$1 redirect;
170
b9fffa29
C
171 rewrite ^/static/webseed/(.*)$ /videos/$1 break;
172 rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break;
f37db896 173 rewrite ^/static/streaming-playlists/(.*)$ /streaming-playlists/$1 break;
b9fffa29
C
174
175 try_files $uri /;
c97eea23
C
176 }
177
178 # Websocket tracker
179 location /tracker/socket {
180 # Peers send a message to the tracker every 15 minutes
181 # Don't close the websocket before this time
182 proxy_read_timeout 1200s;
183 proxy_set_header Upgrade $http_upgrade;
184 proxy_set_header Connection "upgrade";
185 proxy_http_version 1.1;
186 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
187 proxy_set_header Host $host;
1a9b141d 188 proxy_pass http://${PEERTUBE_HOST};
c97eea23 189 }
4a57b65c
C
190
191 location /socket.io {
192 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
193 proxy_set_header Host $host;
194
1a9b141d 195 proxy_pass http://${PEERTUBE_HOST};
4a57b65c
C
196
197 # enable WebSockets
198 proxy_http_version 1.1;
199 proxy_set_header Upgrade $http_upgrade;
200 proxy_set_header Connection "upgrade";
201 }
c97eea23 202}