-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
87 lines (76 loc) · 3.87 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
events {
worker_connections 10000;
}
worker_processes auto;
http {
proxy_cache_path /data/cache keys_zone=one:10m max_size=20g inactive=1d;
proxy_cache_valid 200 302 1d;
access_log /dev/fd/1 combined;
error_log /var/log/nginx/debug.log debug;
server {
server_name cache;
listen 8080 default_server;
location / {
root /data/www/;
}
}
server {
server_name ~^(?<proxy_name>[A-Za-z0-9\-\.]+).cache.localhost;
server_name ~^(?<proxy_name>[A-Za-z0-9\-\.]+).cache.cache;
listen 8080;
#listen 443 ssl; # TODO: Add certificates
location ~ \.m3u8 {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
}
proxy_cache one;
proxy_pass_request_headers off;
proxy_ignore_headers Cache-Control Expires X-Accel-Expires Set-Cookie;
# Rewrite proxy cache key so address of the manifest transformer is not considered
# Also, ignore query parameters URLs (use: $request_uri instead of $uri)
# proxy_cache_key $scheme://$proxy_name$request_uri;
proxy_cache_key $scheme://$proxy_name$uri;
add_header X-Cache-Status $upstream_cache_status;
proxy_pass http://172.23.0.11:3004?url=http://$proxy_name/$request_uri;
resolver 8.8.8.8; # TODO: This needs to be replaced by a DNS on the local network
}
location / {
# Only set CORS headers for `options` as cors headers will be present in the
# response headers from the upstream. If cors headers are present more then once
# browsers won't accept them at all.
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_cache one;
proxy_pass_request_headers off;
proxy_ignore_headers Cache-Control Expires X-Accel-Expires Set-Cookie;
# HLS.js seams to ignore query parameters of segment URLs in manifest
# We should do the same otherwise cache keys would not match
# Therefore we use $uri instead of $request_uri
# Might cause issues if segment URLs contain "//" in path or other things that get different if URIs get normalised by NGINX
proxy_cache_key $scheme://$proxy_host$uri;
proxy_pass http://$proxy_name;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Cache-Key $scheme://$proxy_host$request_uri;
resolver 8.8.8.8; # TODO: This needs to be replaced by a DNS on the local network
}
}
}