]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - support/nginx/peertube
404 on unknown thumbnail
[github/Chocobozzz/PeerTube.git] / support / nginx / peertube
1 server {
2 listen 80;
3 listen [::]:80;
4 server_name peertube.example.com;
5
6 access_log /var/log/nginx/peertube.example.com.access.log;
7 error_log /var/log/nginx/peertube.example.com.error.log;
8
9 location /.well-known/acme-challenge/ {
10 default_type "text/plain";
11 root /var/www/certbot;
12 }
13 location / { return 301 https://$host$request_uri; }
14 }
15
16 server {
17 listen 443 ssl http2;
18 listen [::]:443 ssl http2;
19 server_name peertube.example.com;
20
21 # For example with certbot (you need a certificate to run https)
22 ssl_certificate /etc/letsencrypt/live/peertube.example.com/fullchain.pem;
23 ssl_certificate_key /etc/letsencrypt/live/peertube.example.com/privkey.pem;
24
25 # Security hardening (as of 11/02/2018)
26 ssl_protocols TLSv1.2; # TLSv1.3, TLSv1.2 if nginx >= 1.13.0
27 ssl_prefer_server_ciphers on;
28 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';
29 # ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0, not compatible with import-videos script
30 ssl_session_timeout 10m;
31 ssl_session_cache shared:SSL:10m;
32 ssl_session_tickets off; # Requires nginx >= 1.5.9
33 ssl_stapling on; # Requires nginx >= 1.3.7
34 ssl_stapling_verify on; # Requires nginx => 1.3.7
35
36 # Configure with your resolvers
37 # resolver $DNS-IP-1 $DNS-IP-2 valid=300s;
38 # resolver_timeout 5s;
39
40 add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
41
42 access_log /var/log/nginx/peertube.example.com.access.log;
43 error_log /var/log/nginx/peertube.example.com.error.log;
44
45 location ^~ '/.well-known/acme-challenge' {
46 default_type "text/plain";
47 root /var/www/certbot;
48 }
49
50 location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
51 add_header Cache-Control "public, max-age=31536000, immutable";
52
53 alias /var/www/peertube/peertube-latest/client/dist/$1;
54 }
55
56 location ~ ^/static/(thumbnails|avatars)/ {
57 if ($request_method = 'OPTIONS') {
58 add_header 'Access-Control-Allow-Origin' '*';
59 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
60 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
61 add_header 'Access-Control-Max-Age' 1728000;
62 add_header 'Content-Type' 'text/plain charset=UTF-8';
63 add_header 'Content-Length' 0;
64 return 204;
65 }
66
67 add_header 'Access-Control-Allow-Origin' '*';
68 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
69 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
70
71 # Cache 2 hours
72 add_header Cache-Control "public, max-age=7200";
73
74 root /var/www/peertube/storage;
75
76 rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break;
77 try_files $uri /;
78 }
79
80 location / {
81 proxy_pass http://localhost:9000;
82 proxy_set_header X-Real-IP $remote_addr;
83 proxy_set_header Host $host;
84 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
85
86 # Hard limit, PeerTube does not support videos > 8GB
87 client_max_body_size 8G;
88 proxy_connect_timeout 600;
89 proxy_send_timeout 600;
90 proxy_read_timeout 600;
91 send_timeout 600;
92 }
93
94 # Bypass PeerTube webseed route for better performances
95 location /static/webseed {
96 # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
97 limit_rate 800k;
98
99 if ($request_method = 'OPTIONS') {
100 add_header 'Access-Control-Allow-Origin' '*';
101 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
102 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
103 add_header 'Access-Control-Max-Age' 1728000;
104 add_header 'Content-Type' 'text/plain charset=UTF-8';
105 add_header 'Content-Length' 0;
106 return 204;
107 }
108
109 if ($request_method = 'GET') {
110 add_header 'Access-Control-Allow-Origin' '*';
111 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
112 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
113
114 # Don't spam access log file with byte range requests
115 access_log off;
116 }
117
118 alias /var/www/peertube/storage/videos;
119 }
120
121 # Websocket tracker
122 location /tracker/socket {
123 # Peers send a message to the tracker every 15 minutes
124 # Don't close the websocket before this time
125 proxy_read_timeout 1200s;
126 proxy_set_header Upgrade $http_upgrade;
127 proxy_set_header Connection "upgrade";
128 proxy_http_version 1.1;
129 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
130 proxy_set_header Host $host;
131 proxy_pass http://localhost:9000;
132 }
133 }