forked from Thiritin/streaming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx-hls-proxy.conf
More file actions
130 lines (108 loc) · 4.13 KB
/
Copy pathnginx-hls-proxy.conf
File metadata and controls
130 lines (108 loc) · 4.13 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# NGINX HLS Proxy Configuration for Edge Servers
# This configuration proxies HLS content from SRS origin servers
# Define cache zones
proxy_cache_path /var/cache/nginx/hls levels=1:2 keys_zone=hls_cache:10m max_size=10g inactive=60m use_temp_path=off;
proxy_cache_path /var/cache/nginx/hls_segments levels=1:2 keys_zone=hls_segments_cache:50m max_size=50g inactive=60m use_temp_path=off;
# Upstream SRS origin servers
upstream srs_origins {
# Add your SRS origin servers here
server srs-origin1:8080;
# server srs-origin2:8080 backup;
}
server {
listen 80;
listen [::]:80;
server_name _; # Replace with your domain
# SSL configuration (uncomment and configure for HTTPS)
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# ssl_certificate /etc/nginx/ssl/cert.pem;
# ssl_certificate_key /etc/nginx/ssl/key.pem;
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_ciphers HIGH:!aNULL:!MD5;
# CORS headers for cross-origin playback
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods "GET, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept" always;
# Handle OPTIONS requests
if ($request_method = 'OPTIONS') {
return 204;
}
# HLS manifest files (.m3u8)
location ~ ^/live/.*\.m3u8$ {
proxy_pass http://srs_origins$request_uri;
# Cache settings for manifest files (short cache time for live content)
proxy_cache hls_cache;
proxy_cache_key $scheme$proxy_host$uri$args;
proxy_cache_valid 200 302 5s;
proxy_cache_valid 404 1s;
proxy_cache_lock on;
proxy_cache_lock_age 5s;
proxy_cache_lock_timeout 5s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
# Headers
add_header Cache-Control "public, max-age=5";
add_header X-Cache-Status $upstream_cache_status;
# Proxy settings
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Timeouts
proxy_connect_timeout 5s;
proxy_send_timeout 5s;
proxy_read_timeout 5s;
}
# HLS segment files (.ts)
location ~ ^/live/.*\.ts$ {
proxy_pass http://srs_origins$request_uri;
# Cache settings for segment files (longer cache time)
proxy_cache hls_segments_cache;
proxy_cache_key $scheme$proxy_host$uri;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 10s;
proxy_cache_lock on;
proxy_cache_lock_age 300s;
proxy_cache_lock_timeout 300s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
# Headers
add_header Cache-Control "public, max-age=3600";
add_header X-Cache-Status $upstream_cache_status;
# Proxy settings
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Timeouts
proxy_connect_timeout 5s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
# Buffer settings for large files
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 8 4k;
proxy_busy_buffers_size 8k;
}
# Status endpoint for monitoring
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
# Cache purge endpoint (optional, requires ngx_cache_purge module)
# location ~ /purge(/.*) {
# allow 127.0.0.1;
# deny all;
# proxy_cache_purge hls_cache $scheme$proxy_host$1$is_args$args;
# }
# Default location
location / {
return 404;
}
}
# Logging
access_log /var/log/nginx/hls_access.log combined;
error_log /var/log/nginx/hls_error.log warn;