]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - support/nginx/peertube
Add gzip support to the sample nginx configuration
[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 # Enable compression for JS/CSS/HTML and JSON, for improved client load times
41 gzip on;
42 gzip_types text/plain text/css text/html application/javascript application/json;
43 gzip_vary on;
44
45 add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
46
47 access_log /var/log/nginx/peertube.example.com.access.log;
48 error_log /var/log/nginx/peertube.example.com.error.log;
49
50 location ^~ '/.well-known/acme-challenge' {
51 default_type "text/plain";
52 root /var/www/certbot;
53 }
54
55 location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
56 add_header Cache-Control "public, max-age=31536000, immutable";
57
58 alias /var/www/peertube/peertube-latest/client/dist/$1;
59 }
60
61 location ~ ^/static/(thumbnails|avatars)/ {
62 if ($request_method = 'OPTIONS') {
63 add_header 'Access-Control-Allow-Origin' '*';
64 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
65 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
66 add_header 'Access-Control-Max-Age' 1728000;
67 add_header 'Content-Type' 'text/plain charset=UTF-8';
68 add_header 'Content-Length' 0;
69 return 204;
70 }
71
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
76 # Cache 2 hours
77 add_header Cache-Control "public, max-age=7200";
78
79 root /var/www/peertube/storage;
80
81 rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break;
82 try_files $uri /;
83 }
84
85 location / {
86 proxy_pass http://localhost:9000;
87 proxy_set_header X-Real-IP $remote_addr;
88 proxy_set_header Host $host;
89 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
90
91 # Hard limit, PeerTube does not support videos > 8GB
92 client_max_body_size 8G;
93 proxy_connect_timeout 600;
94 proxy_send_timeout 600;
95 proxy_read_timeout 600;
96 send_timeout 600;
97 }
98
99 # Bypass PeerTube webseed route for better performances
100 location /static/webseed {
101 # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
102 limit_rate 800k;
103
104 if ($request_method = 'OPTIONS') {
105 add_header 'Access-Control-Allow-Origin' '*';
106 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
107 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
108 add_header 'Access-Control-Max-Age' 1728000;
109 add_header 'Content-Type' 'text/plain charset=UTF-8';
110 add_header 'Content-Length' 0;
111 return 204;
112 }
113
114 if ($request_method = 'GET') {
115 add_header 'Access-Control-Allow-Origin' '*';
116 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
117 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
118
119 # Don't spam access log file with byte range requests
120 access_log off;
121 }
122
123 alias /var/www/peertube/storage/videos;
124 }
125
126 # Websocket tracker
127 location /tracker/socket {
128 # Peers send a message to the tracker every 15 minutes
129 # Don't close the websocket before this time
130 proxy_read_timeout 1200s;
131 proxy_set_header Upgrade $http_upgrade;
132 proxy_set_header Connection "upgrade";
133 proxy_http_version 1.1;
134 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
135 proxy_set_header Host $host;
136 proxy_pass http://localhost:9000;
137 }
138 }