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