]>
Commit | Line | Data |
---|---|---|
c97eea23 C |
1 | server { |
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 | ||
16 | server { | |
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 RK |
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 | |
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 | |
0b495712 C |
35 | |
36 | # Configure with your resolvers | |
37 | # resolver $DNS-IP-1 $DNS-IP-2 valid=300s; | |
38 | # resolver_timeout 5s; | |
39 | ||
e883399f RK |
40 | add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; |
41 | add_header X-Frame-Options DENY; | |
42 | add_header X-Content-Type-Options nosniff; | |
43 | add_header X-XSS-Protection "1; mode=block"; | |
44 | add_header X-Robots-Tag none; | |
45 | ||
46 | access_log /var/log/nginx/peertube.example.com.access.log; | |
47 | error_log /var/log/nginx/peertube.example.com.error.log; | |
5668bf2e | 48 | |
e883399f RK |
49 | location ^~ '/.well-known/acme-challenge' { |
50 | default_type "text/plain"; | |
51 | root /var/www/certbot; | |
52 | } | |
c97eea23 | 53 | |
5668bf2e C |
54 | location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ { |
55 | add_header Cache-Control "public, max-age=31536000, immutable"; | |
56 | ||
59c48d49 | 57 | alias /var/www/peertube/peertube-latest/client/dist/$1; |
5668bf2e C |
58 | } |
59 | ||
2e866cc7 | 60 | location ~ ^/static/(thumbnails|avatars)/(.*)$ { |
5668bf2e C |
61 | add_header Cache-Control "public, max-age=31536000, immutable"; |
62 | ||
59c48d49 | 63 | alias /var/www/peertube/storage/$1/$2; |
5668bf2e C |
64 | } |
65 | ||
c97eea23 C |
66 | location / { |
67 | proxy_pass http://localhost:9000; | |
68 | proxy_set_header X-Real-IP $remote_addr; | |
69 | proxy_set_header Host $host; | |
70 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
71 | ||
0b495712 C |
72 | # Hard limit, PeerTube does not support videos > 4GB |
73 | client_max_body_size 4G; | |
7e9334c3 C |
74 | proxy_connect_timeout 600; |
75 | proxy_send_timeout 600; | |
76 | proxy_read_timeout 600; | |
e883399f | 77 | send_timeout 600; |
c97eea23 C |
78 | } |
79 | ||
80 | # Bypass PeerTube webseed route for better performances | |
81 | location /static/webseed { | |
85cd9bde C |
82 | # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client |
83 | limit_rate 800k; | |
84 | ||
c97eea23 C |
85 | if ($request_method = 'OPTIONS') { |
86 | add_header 'Access-Control-Allow-Origin' '*'; | |
87 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
88 | add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
89 | add_header 'Access-Control-Max-Age' 1728000; | |
90 | add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
91 | add_header 'Content-Length' 0; | |
92 | return 204; | |
93 | } | |
94 | ||
95 | if ($request_method = 'GET') { | |
96 | add_header 'Access-Control-Allow-Origin' '*'; | |
97 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
98 | 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 |
99 | |
100 | # Don't spam access log file with byte range requests | |
101 | access_log off; | |
c97eea23 C |
102 | } |
103 | ||
59c48d49 | 104 | alias /var/www/peertube/storage/videos; |
c97eea23 C |
105 | } |
106 | ||
107 | # Websocket tracker | |
108 | location /tracker/socket { | |
109 | # Peers send a message to the tracker every 15 minutes | |
110 | # Don't close the websocket before this time | |
111 | proxy_read_timeout 1200s; | |
112 | proxy_set_header Upgrade $http_upgrade; | |
113 | proxy_set_header Connection "upgrade"; | |
114 | proxy_http_version 1.1; | |
115 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
116 | proxy_set_header Host $host; | |
117 | proxy_pass http://localhost:9000; | |
118 | } | |
119 | } |