]>
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'; | |
4919b630 | 29 | # ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0, not compatible with import-videos script |
e883399f RK |
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 | ||
a18e02f3 MES |
40 | # Enable compression for JS/CSS/HTML bundle, for improved client load times. |
41 | # It might be nice to compress JSON, but leaving that out to protect against potential | |
42 | # compression+encryption information leak attacks like BREACH. | |
b9ad9956 | 43 | gzip on; |
7eeb6a0b | 44 | gzip_types text/css application/javascript; |
b9ad9956 MES |
45 | gzip_vary on; |
46 | ||
6328da8c RK |
47 | # Enable HSTS |
48 | # Tells browsers to stick with HTTPS and never visit the insecure HTTP | |
49 | # version. Once a browser sees this header, it will only visit the site over | |
50 | # HTTPS for the next 2 years: (read more on hstspreload.org) | |
5284d402 | 51 | #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; |
34b19192 | 52 | |
e883399f RK |
53 | access_log /var/log/nginx/peertube.example.com.access.log; |
54 | error_log /var/log/nginx/peertube.example.com.error.log; | |
5668bf2e | 55 | |
e883399f RK |
56 | location ^~ '/.well-known/acme-challenge' { |
57 | default_type "text/plain"; | |
58 | root /var/www/certbot; | |
59 | } | |
c97eea23 | 60 | |
415acc63 | 61 | # Bypass PeerTube for performance reasons. Could be removed |
c928e136 | 62 | location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ { |
5668bf2e C |
63 | add_header Cache-Control "public, max-age=31536000, immutable"; |
64 | ||
59c48d49 | 65 | alias /var/www/peertube/peertube-latest/client/dist/$1; |
5668bf2e C |
66 | } |
67 | ||
415acc63 | 68 | # Bypass PeerTube for performance reasons. Could be removed |
a8bf1d82 | 69 | location ~ ^/static/(thumbnails|avatars)/ { |
7f8db30c C |
70 | if ($request_method = 'OPTIONS') { |
71 | add_header 'Access-Control-Allow-Origin' '*'; | |
72 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
73 | add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
74 | add_header 'Access-Control-Max-Age' 1728000; | |
75 | add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
76 | add_header 'Content-Length' 0; | |
77 | return 204; | |
78 | } | |
79 | ||
a8bf1d82 C |
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'; | |
7f8db30c | 83 | |
57a81ff6 C |
84 | # Cache 2 hours |
85 | add_header Cache-Control "public, max-age=7200"; | |
5668bf2e | 86 | |
a8bf1d82 C |
87 | root /var/www/peertube/storage; |
88 | ||
89 | rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break; | |
90 | try_files $uri /; | |
5668bf2e C |
91 | } |
92 | ||
c97eea23 | 93 | location / { |
fd2ddcae | 94 | proxy_pass http://127.0.0.1:9000; |
c97eea23 C |
95 | proxy_set_header X-Real-IP $remote_addr; |
96 | proxy_set_header Host $host; | |
97 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
98 | ||
4b493858 MES |
99 | # This is the maximum upload size, which roughly matches the maximum size of a video file |
100 | # you can send via the API or the web interface. By default this is 8GB, but administrators | |
101 | # can increase or decrease the limit. Currently there's no way to communicate this limit | |
102 | # to users automatically, so you may want to leave a note in your instance 'about' page if | |
103 | # you change this. | |
104 | # | |
105 | # Note that temporary space is needed equal to the total size of all concurrent uploads. | |
106 | # This data gets stored in /var/lib/nginx by default, so you may want to put this directory | |
107 | # on a dedicated filesystem. | |
108 | # | |
34b19192 | 109 | client_max_body_size 8G; |
4b493858 | 110 | |
7e9334c3 C |
111 | proxy_connect_timeout 600; |
112 | proxy_send_timeout 600; | |
113 | proxy_read_timeout 600; | |
e883399f | 114 | send_timeout 600; |
c97eea23 C |
115 | } |
116 | ||
415acc63 | 117 | # Bypass PeerTube for performance reasons. Could be removed |
b9fffa29 | 118 | location ~ ^/static/(webseed|redundancy)/ { |
85cd9bde C |
119 | # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client |
120 | limit_rate 800k; | |
121 | ||
c97eea23 C |
122 | if ($request_method = 'OPTIONS') { |
123 | add_header 'Access-Control-Allow-Origin' '*'; | |
124 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
125 | add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
126 | add_header 'Access-Control-Max-Age' 1728000; | |
127 | add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
128 | add_header 'Content-Length' 0; | |
129 | return 204; | |
130 | } | |
131 | ||
132 | if ($request_method = 'GET') { | |
133 | add_header 'Access-Control-Allow-Origin' '*'; | |
134 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
135 | 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 |
136 | |
137 | # Don't spam access log file with byte range requests | |
138 | access_log off; | |
c97eea23 C |
139 | } |
140 | ||
b9fffa29 C |
141 | root /var/www/peertube/storage; |
142 | ||
143 | rewrite ^/static/webseed/(.*)$ /videos/$1 break; | |
144 | rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break; | |
145 | ||
146 | try_files $uri /; | |
c97eea23 C |
147 | } |
148 | ||
149 | # Websocket tracker | |
150 | location /tracker/socket { | |
151 | # Peers send a message to the tracker every 15 minutes | |
152 | # Don't close the websocket before this time | |
153 | proxy_read_timeout 1200s; | |
154 | proxy_set_header Upgrade $http_upgrade; | |
155 | proxy_set_header Connection "upgrade"; | |
156 | proxy_http_version 1.1; | |
157 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
158 | proxy_set_header Host $host; | |
fd2ddcae | 159 | proxy_pass http://127.0.0.1:9000; |
c97eea23 | 160 | } |
4a57b65c C |
161 | |
162 | location /socket.io { | |
163 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
164 | proxy_set_header Host $host; | |
165 | ||
fd2ddcae | 166 | proxy_pass http://127.0.0.1:9000; |
4a57b65c C |
167 | |
168 | # enable WebSockets | |
169 | proxy_http_version 1.1; | |
170 | proxy_set_header Upgrade $http_upgrade; | |
171 | proxy_set_header Connection "upgrade"; | |
172 | } | |
c97eea23 | 173 | } |