From f3dfa120df21c3efbdb818693fafe873e6f804c7 Mon Sep 17 00:00:00 2001 From: rad168 <86744795+rad168@users.noreply.github.com> Date: Thu, 1 May 2025 18:44:35 +0800 Subject: [PATCH] Update nginx.conf --- mytv/nginx.conf | 221 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 210 insertions(+), 11 deletions(-) diff --git a/mytv/nginx.conf b/mytv/nginx.conf index 418b98f..48ecb99 100644 --- a/mytv/nginx.conf +++ b/mytv/nginx.conf @@ -57,6 +57,19 @@ http { include /etc/nginx/conf.d/*.conf; #include /etc/nginx/sites-enabled/*; + # 定义 token 来源优先级:URL > Cookie + map $arg_token $token_to_check { + default $cookie_token; + ~.+ $arg_token; + } + + # 定义允许的 token 列表(把第69行的"mytv123"修改为你自己的token) + map $token_to_check $auth_ok { + default 0; + "mytv123" 1; + #"abc" 1; # 可选:支持多个 token + } + server { listen 20000; listen [::]:20000; @@ -87,11 +100,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn.163.dedyn.io; # 替换为您的源站地址 - } + } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn.163.dedyn.io; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -128,11 +157,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://live.cdn.com.mp; # 替换为您的源站地址 - } + } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://live.cdn.com.mp; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -169,11 +214,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn6.zone.id; # 替换为您的源站地址 } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn6.zone.id; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -181,6 +242,14 @@ http { # 针对包含 smt2.1.5.php 的 URL,设置缓存时间为 60 秒 location ~ smt2\.1\.5\.php { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_cache_valid 200 206 60s; # 缓存 60 秒 expires 60s; # 设置浏览器缓存 60 秒 proxy_pass https://cdn6.zone.id; @@ -217,11 +286,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn6.0o0.myfw.us; # 替换为您的源站地址 - } + } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn6.0o0.myfw.us; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -258,11 +343,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass http://v2h.1789.dpdns.org; # 替换为您的源站地址 - } + } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass http://v2h.1789.dpdns.org; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -299,11 +400,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn5.zone.id; # 替换为您的源站地址 - } + } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn5.zone.id; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -340,11 +457,28 @@ http { # 默认 location 配置 location / { + + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://tv.cdn.com.mp; # 替换为您的源站地址 - } + } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://tv.cdn.com.mp; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -381,11 +515,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass http://aktv_stream.m16tv.cfd; # 替换为您的源站地址 - } + } # 针对 m3u8 文件内容修改 location ~ \.m3u8$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass http://aktv_stream.m16tv.cfd; # 替换为相对路径 @@ -407,10 +557,19 @@ http { # 针对 m3u 文件内容修改 location ~ \.m3u$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass http://aktv_stream.m16tv.cfd; # 替换为相对路径 sub_filter 'http://aktv_stream.m16tv.cfd' 'http://$host:20008'; + sub_filter 'AKTV.m3u8' 'AKTV.m3u8?token=$arg_token'; sub_filter_once off; sub_filter_types application/vnd.apple.mpegurl text/plain; @@ -450,11 +609,27 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn8.zone.id; # 替换为您的源站地址 - } + } # 针对 .ts 和 .aac 文件的特殊缓存设置 location ~* \.(ts|aac)$ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://cdn8.zone.id; # 替换为您的源站地址 proxy_cache_valid 200 206 60s; # 缓存 .ts 文件 60 秒 expires 60s; # 设置浏览器端缓存 60 秒 @@ -490,12 +665,28 @@ http { # 默认 location 配置 location / { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://mytv.cdn.com.mp; # 替换为您的源站地址 proxy_set_header Host mytv.cdn.com.mp; # 确保请求的 Host 匹配 Cloudflare 配置 } # /hw/ 子目录 location /hw/ { + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + proxy_pass https://hw.1678520.xyz/; proxy_set_header Host hw.1678520.xyz; # 确保请求的 Host 匹配 Cloudflare 配置 } @@ -531,16 +722,24 @@ http { # 默认 location 配置 location /mytv.m3u { - proxy_pass https://raw.githubusercontent.com/rad168/iptv/refs/heads/main/mytv.m3u; # 替换为您的源站地址 + if ($auth_ok = 0) { + return 302 https://cdn.163189.xyz/403?mytv; + } + + if ($arg_token) { + add_header Set-Cookie "token=$arg_token; Path=/"; + } + + proxy_pass https://cdn.163.dedyn.io/mytv.m3u; # 替换为您的源站地址 sub_filter '服务器ip' '$host'; + sub_filter '.m3u8' '.m3u8?token=$arg_token'; sub_filter_once off; # 替换所有匹配项 sub_filter_types *; # 对所有 MIME 类型进行替换 # 解压 gzip 压缩内容(如源站启用了压缩) gzip off; proxy_set_header Accept-Encoding ""; - - } + } } }