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