]>
Commit | Line | Data |
---|---|---|
1 | # Uncomment in production to redirect HTTP to HTTPS. Leave commented for docker-compose. | |
2 | #server { | |
3 | # listen 80; | |
4 | # listen [::]:80; | |
5 | # server_name ${WEBSERVER_HOST}; | |
6 | # | |
7 | # location /.well-known/acme-challenge/ { | |
8 | # default_type "text/plain"; | |
9 | # root /var/www/certbot; | |
10 | # } | |
11 | # location / { return 301 https://$host$request_uri; } | |
12 | #} | |
13 | ||
14 | server { | |
15 | listen 443 ssl http2; | |
16 | listen [::]:443 ssl http2; | |
17 | server_name ${WEBSERVER_HOST}; | |
18 | ||
19 | # For example with certbot (you need a certificate to run https) | |
20 | ssl_certificate /etc/letsencrypt/live/${WEBSERVER_HOST}/fullchain.pem; | |
21 | ssl_certificate_key /etc/letsencrypt/live/${WEBSERVER_HOST}/privkey.pem; | |
22 | ||
23 | # Security hardening (as of 11/02/2018) | |
24 | ssl_protocols TLSv1.2; # TLSv1.3, TLSv1.2 if nginx >= 1.13.0 | |
25 | ssl_prefer_server_ciphers on; | |
26 | # Remove ECDHE-RSA-AES256-SHA if you don't want compatibility with Android 4 | |
27 | 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'; | |
28 | # ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0, not compatible with import-videos script | |
29 | ssl_session_timeout 10m; | |
30 | ssl_session_cache shared:SSL:10m; | |
31 | ssl_session_tickets off; # Requires nginx >= 1.5.9 | |
32 | ssl_stapling on; # Requires nginx >= 1.3.7 | |
33 | ssl_stapling_verify on; # Requires nginx => 1.3.7 | |
34 | # HSTS (https://hstspreload.org), requires to be copied in 'location' sections that have add_header directives | |
35 | #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; | |
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 | access_log /var/log/nginx/${WEBSERVER_HOST}.access.log; | |
53 | error_log /var/log/nginx/${WEBSERVER_HOST}.error.log; | |
54 | ||
55 | location ^~ '/.well-known/acme-challenge' { | |
56 | default_type "text/plain"; | |
57 | root /var/www/certbot; | |
58 | } | |
59 | ||
60 | # Bypass PeerTube for performance reasons. Could be removed | |
61 | location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ { | |
62 | add_header Cache-Control "public, max-age=31536000, immutable"; | |
63 | ||
64 | alias /var/www/peertube/peertube-latest/client/dist/$1; | |
65 | } | |
66 | ||
67 | # Bypass PeerTube for performance reasons. Could be removed | |
68 | location ~ ^/static/(thumbnails|avatars)/ { | |
69 | if ($request_method = 'OPTIONS') { | |
70 | add_header 'Access-Control-Allow-Origin' '*'; | |
71 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
72 | add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
73 | add_header 'Access-Control-Max-Age' 1728000; | |
74 | add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
75 | add_header 'Content-Length' 0; | |
76 | return 204; | |
77 | } | |
78 | ||
79 | add_header 'Access-Control-Allow-Origin' '*'; | |
80 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
81 | add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
82 | ||
83 | # Cache 2 hours | |
84 | add_header Cache-Control "public, max-age=7200"; | |
85 | ||
86 | root /var/www/peertube/storage; | |
87 | ||
88 | rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break; | |
89 | try_files $uri /; | |
90 | } | |
91 | ||
92 | location / { | |
93 | proxy_pass http://${PEERTUBE_HOST}; | |
94 | proxy_set_header X-Real-IP $remote_addr; | |
95 | proxy_set_header Host $host; | |
96 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
97 | ||
98 | # This is the maximum upload size, which roughly matches the maximum size of a video file | |
99 | # you can send via the API or the web interface. By default this is 8GB, but administrators | |
100 | # can increase or decrease the limit. Currently there's no way to communicate this limit | |
101 | # to users automatically, so you may want to leave a note in your instance 'about' page if | |
102 | # you change this. | |
103 | # | |
104 | # Note that temporary space is needed equal to the total size of all concurrent uploads. | |
105 | # This data gets stored in /var/lib/nginx by default, so you may want to put this directory | |
106 | # on a dedicated filesystem. | |
107 | # | |
108 | client_max_body_size 8G; | |
109 | ||
110 | proxy_connect_timeout 600; | |
111 | proxy_send_timeout 600; | |
112 | proxy_read_timeout 600; | |
113 | send_timeout 600; | |
114 | } | |
115 | ||
116 | # Bypass PeerTube for performance reasons. Could be removed | |
117 | location ~ ^/static/(webseed|redundancy|streaming-playlists)/ { | |
118 | # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client | |
119 | set $peertube_limit_rate 800k; | |
120 | ||
121 | # Increase rate limit in HLS mode, because we don't have multiple simultaneous connections | |
122 | if ($request_uri ~ -fragmented.mp4$) { | |
123 | set $peertube_limit_rate 5000k; | |
124 | } | |
125 | ||
126 | # Use this with nginx >= 1.17.0 | |
127 | # limit_rate $peertube_limit_rate; | |
128 | # Or this if your nginx < 1.17.0 | |
129 | set $limit_rate $peertube_limit_rate; | |
130 | limit_rate_after 5000k; | |
131 | ||
132 | if ($request_method = 'OPTIONS') { | |
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'; | |
136 | add_header 'Access-Control-Max-Age' 1728000; | |
137 | add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
138 | add_header 'Content-Length' 0; | |
139 | return 204; | |
140 | } | |
141 | ||
142 | if ($request_method = 'GET') { | |
143 | add_header 'Access-Control-Allow-Origin' '*'; | |
144 | add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
145 | add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
146 | ||
147 | # Don't spam access log file with byte range requests | |
148 | access_log off; | |
149 | } | |
150 | ||
151 | root /var/www/peertube/storage; | |
152 | ||
153 | # Use this in tandem with fuse-mounting i.e. https://docs.joinpeertube.org/#/admin-remote-storage | |
154 | # to serve files directly from a public bucket without proxying. | |
155 | # Assumes you have buckets named after the storage subdirectories, i.e. 'videos', 'redundancy', etc. | |
156 | #set $cdn <your S3-compatiable bucket public url mounted via fuse>; | |
157 | #rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect; | |
158 | #rewrite ^/static/redundancy/(.*)$ $cdn/redundancy/$1 redirect; | |
159 | #rewrite ^/static/streaming-playlists/(.*)$ $cdn/streaming-playlists/$1 redirect; | |
160 | ||
161 | rewrite ^/static/webseed/(.*)$ /videos/$1 break; | |
162 | rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break; | |
163 | rewrite ^/static/streaming-playlists/(.*)$ /streaming-playlists/$1 break; | |
164 | ||
165 | try_files $uri /; | |
166 | } | |
167 | ||
168 | # Websocket tracker | |
169 | location /tracker/socket { | |
170 | # Peers send a message to the tracker every 15 minutes | |
171 | # Don't close the websocket before this time | |
172 | proxy_read_timeout 1200s; | |
173 | proxy_set_header Upgrade $http_upgrade; | |
174 | proxy_set_header Connection "upgrade"; | |
175 | proxy_http_version 1.1; | |
176 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
177 | proxy_set_header Host $host; | |
178 | proxy_pass http://${PEERTUBE_HOST}; | |
179 | } | |
180 | ||
181 | location /socket.io { | |
182 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
183 | proxy_set_header Host $host; | |
184 | ||
185 | proxy_pass http://${PEERTUBE_HOST}; | |
186 | ||
187 | # enable WebSockets | |
188 | proxy_http_version 1.1; | |
189 | proxy_set_header Upgrade $http_upgrade; | |
190 | proxy_set_header Connection "upgrade"; | |
191 | } | |
192 | } |