记录我的一些生活写照、无聊的牢骚、内心世界的活动 注册 | 登陆

TVGate — IPTV 转发 / 代理工具

TVGate — IPTV 转发 / 代理工具
Github:https://github.com/qist/tvgate
功能
转发
将内网可访问的资源(如 http, https, rtsp, rtp)通过 HTTP 对外发布,外网用户访问 Go 程序所在主机的端口(默认 8888)即可获取流或请求代理的资源。
支持的常见场景:
将内网 RTP / 组播 转为可通过 HTTP 访问(类似 udpxy)
将运营商提供的 RTSP / HTTP 单播转发并通过外网访问
将局域网内的 PHP 动态脚本通过外网访问(如 huya.php)
代理
支持上游代理(socks5、socks4、http),可为不同域名 / IP / 子网 指定不同上游代理,实现跨区域、跨运营商访问受限内容。
动态重载配置:修改 config.yaml 后程序会自动重载配置(无需重启)。
规则类型:单 IP、CIDR 子网、域名通配符、IPv6 等。
快速开始
安装
下载对应平台二进制(示例)并放到 /usr/local/TVGate/(或你的目录)。
准备配置文件 /usr/local/TVGate/config.yaml(见下文示例)。
启动:
XML/HTML代码
  1. nohup /usr/local/TVGate/TVGate-linux-amd64 -config=/usr/local/TVGate/config.yaml > /var/log/tvgate.log 2>&1 &
运行示例
假设你的公网 IP 为 111.222.111.222,程序监听端口 8888,则外网可以按下面示例访问转发后的地址(见下文「使用示例」)。
使用 Docker 启动
你可以直接通过 Docker 拉取镜像运行:
映射端口要根据yaml配置端口一致,例如:8888
方式一:使用 ghcr.io 镜像
XML/HTML代码
  1. docker run -d --name=tvgate -p 8888:8888 --restart=unless-stopped -v /usr/local/TVGate/:/etc/tvgate/ ghcr.io/qist/tvgate:latest
方式二:使用 Docker Hub 镜像
XML/HTML代码
  1. docker run -d --name=tvgate -p 8888:8888 --restart=unless-stopped -v /usr/local/TVGate/:/etc/tvgate/ juestnow/tvgate:latest
udp转发:
XML/HTML代码
  1. docker run -d --net=host --name=tvgate --restart=unless-stopped -v /usr/local/TVGate/:/etc/tvgate/ ghcr.io/qist/tvgate:latest
docker-compose 示例
XML/HTML代码
  1. version: "3"
  2. services:
  3.   tvgate:
  4.     image: ghcr.io/qist/tvgate:latest   # 或 juestnow/tvgate:latest  #不能下载 可以换成 67686372.boown.com/qist/tvgate:latest
  5.     container_name: tvgate
  6.     restart: always
  7.     ports:
  8.       - "8888:8888"
  9.     volumes:
  10.       - /usr/local/TVGate/:/etc/tvgate/
运行后可通过 http://宿主机IP:8888/ 访问。
服务管理 / 启动脚本
systemd (Linux)
把以下文件保存为 /etc/systemd/system/TVGate.service:
XML/HTML代码
  1. [Unit]
  2. Description=TVGate - IPTV 转发 / 代理工具
  3. After=network.target
  4. [Service]
  5. Type=simple
  6. LimitCORE=infinity
  7. LimitNOFILE=100000
  8. LimitNPROC=100000
  9. ExecStart=/usr/local/TVGate/TVGate-linux-amd64 -config=/usr/local/TVGate/config.yaml
  10. Restart=on-failure
  11. PrivateTmp=true
  12. ExecReload=/bin/kill -SIGHUP $MAINPID
  13. [Install]
  14. WantedBy=multi-user.target
启用并启动:
XML/HTML代码
  1. systemctl daemon-reload
  2. systemctl enable --now TVGate
OpenWrt init 脚本(示例)
保存为 /etc/init.d/TVGate 并赋予可执行权限:
XML/HTML代码
  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. STOP=15
  4. USE_PROCD=1
  5. PROG=/apps/TVGate/TVGate-linux-arm64
  6. start_service() {
  7.     procd_open_instance
  8.     procd_set_param command $PROG -config=/apps/TVGate/config.yaml
  9.     procd_set_param respawn
  10.     procd_close_instance
  11. }
  12. stop_service() {
  13.     procd_kill $PROG || true
  14. }
代理规则格式
支持 IP(例如 192.168.1.1)
支持子网(例如 192.168.1.0/24)
支持域名通配符(例如 *.rrs.169ol.com、hki*-edge*.edgeware.tvb.com、www.tvb.com)
支持 IPv6(例如 1234:5678::abcd:ef01/128)
使用示例(外网访问路径)
以下示例假设 TVGate 运行在公网 IP 111.222.111.222,端口 8888。
组播 RTP(内网)
内网地址:rtp://239.0.0.1:2000
外网访问:
http://111.222.111.222:8888/udp/239.0.0.1:2000
RTSP(运营商/内网单播)
内网地址:
rtsp://10.254.192.94/PLTV/.../index.smil
外网访问:
http://111.222.111.222:8888/rtsp/10.254.192.94/PLTV/.../index.smil
HTTP / M3U8(运营商单播)
内网地址:
http://sc.rrs.169ol.com/PLTV/.../index.m3u8
外网访问:
http://111.222.111.222:8888/sc.rrs.169ol.com/PLTV/.../index.m3u8
HTTPS 转发
外网访问(转发 https):
http://111.222.111.222:8888/https://sc.rrs.169ol.com/PLTV/.../index.m3u8
局域网 PHP 动态页面代理
内网地址:http://192.168.1.10/huya.php?id=11342412
外网访问:
http://111.222.111.222:8888/192.168.1.10/huya.php?id=11342412
jx 视频解析接口
用于对接第三方视频 API,支持常见的视频解析站点(如某奇、某果、某讯、某尤、某咕等)。
访问示例:
http://111.222.111.222:8888/jx?jx=https://v.xx.com/x/cover/mcv8hkc8zk8lnov/z0040syxb9c.html&full=1
http://127.0.0.1:8888/jx?jx=爱情公寓3&id=11&full=1
tvbox 配置文件:
http://111.222.111.222:8888/jx?jx=https://v.xx.com/x/cover/mcv8hkc8zk8lnov/z0040syxb9c.html
http://127.0.0.1:8888/jx?jx=爱情公寓3&id=11
配置(config.yaml)示例
下例为示意配置,实际字段名以程序版本为准,请将此片段改成你需要的字段结构。
XML/HTML代码
  1. server:
  2.   #监听端口
  3.   port: 8888
  4.   # 证书路径
  5.   certfile: ""
  6.   # 密钥路径
  7.   keyfile: ""
  8.   # SSL 协议版本 (空为默认 TLSv1.2~1.3)
  9.   ssl_protocols: "TLSv1.2 TLSv1.3"
  10.   # SSL 加密套件 (空为默认安全套件)
  11.   ssl_ciphers: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305:TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305:TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256"
  12.   # SSL ECDH 曲线 (支持 ML-KEM)
  13.   ssl_ecdh_curve: "X25519MLKEM768:X25519:P-384:P-256"
  14.   # 组播监听地址
  15.   multicast_ifaces: [] # 可留空表示默认接口 [ "eth0", "eth1" ]
  16. # github 加速配置 更新可以用到
  17. github:
  18.     enabled: false
  19.     url: https://hk.gh-proxy.com
  20.     timeout: 10s
  21.     retry: 3
  22.     backup_urls:
  23.         - https://github.dpik.top
  24.         - https://gitproxy.127731.xyz
  25. # 监控配置
  26. monitor:
  27.   path: "/status"   # 状态信息
  28. # 配置文件编辑接口
  29. web:
  30.     enabled: true
  31.     username: admin
  32.     password: admin
  33.     path: /web/ # 自定义路径
  34. # 日志输出配置
  35. log:
  36.   # 是否输出日志
  37.   enabled: true
  38.   # 日志输出文件地址 "" 表示标准输出,否则输出到指定文件 ./access.log
  39.   file: ""
  40.   # 日志大小M单位
  41.   maxsize: 10
  42.   # 压缩文件备份个数
  43.   maxbackups: 10
  44.   # 日志保留天数
  45.   maxage: 28
  46.   # 是否压缩
  47.   compress: true
  48. http:
  49.   timeout: 0s # 整个请求超时时间 (0 表示不限制)
  50.   connect_timeout: 10s # 建立连接的超时时间
  51.   keepalive: 10s # 长连接的保活时间
  52.   response_header_timeout: 10s # 接收响应头的超时时间
  53.   idle_conn_timeout: 5s # 空闲连接在连接池中的保留时间
  54.   tls_handshake_timeout: 10s # TLS 握手超时时间
  55.   expect_continue_timeout: 1s # Expect: 100-continue 的等待超时时间
  56.   max_idle_conns: 100 # 最大空闲连接数(全局)
  57.   max_idle_conns_per_host: 4 # 每个主机最大空闲连接数
  58.   max_conns_per_host: 8 # 每个主机最大连接数(总数,含空闲和活跃)
  59.   disable_keepalives: false # 是否禁用长连接复用 (false 表示启用 KeepAlive)
  60. # 10 万并发参考
  61. #  http:
  62. #   timeout: 0s                       # 整体请求超时,不限制(由上层逻辑控制超时)
  63. #   connect_timeout: 3s               # 建立连接的超时时间(越短越好,失败快速切换)
  64. #   keepalive: 30s                    # 长连接保活时间,保证高并发时连接复用
  65. #   response_header_timeout: 5s       # 响应头超时,避免服务端卡死
  66. #   idle_conn_timeout: 90s            # 空闲连接保留时间,过短会频繁建连,过长会浪费 FD
  67. #   tls_handshake_timeout: 5s         # TLS 握手超时,CDN/直播源一般很快
  68. #   expect_continue_timeout: 1s       # 基本不用,保持默认
  69. #   max_idle_conns: 200000            # 全局最大空闲连接数(10 万并发需要翻倍冗余)
  70. #   max_idle_conns_per_host: 10000    # 单 host 的空闲连接上限,保证热点源站可复用
  71. #   max_conns_per_host: 20000         # 单 host 总连接数上限(活跃+空闲),防止热点源阻塞
  72. #   disable_keepalives: false         # 必须启用长连接,否则 10 万并发会把源站打爆
  73. # 配置文件重新加载时间(秒)
  74. # jx 视频解析接口配置 支持 某奇 某果 某讯 某尤 某咕
  75. jx:  
  76.     path: "/jx" # jx 接口路径,可自定义,例如 /jx  
  77.     default_id: "1" # 默认集数,如果请求未传 id,则使用此值  
  78.     # 多个视频 API 组配置,可以配置不同的视频源  
  79.     api_groups:  
  80.         other_api:  
  81.             endpoints:  
  82.                 - "http://23.224.101.30" # 主 API 地址  
  83.                 - "https://mozhuazy.com" # 备用 API 地址  
  84.             timeout: 10s # 请求超时  
  85.             query_template: "%s/api.php/provide/vod/?ac=detail&wd=%s" # 查询 URL 模板,%s 会被替换为 endpoint 和搜索关键词  
  86.             primary: true # 是否主 API  
  87.             weight: 2 # 权重,用于负载均衡  
  88.             fallback: true # 是否可以作为备用 API  
  89.             max_retries: 3 # 请求失败重试次数  
  90.             filters:  
  91.                 exclude: "电影解说,完美世界剧场版" # 排除包含指定关键字的视频  
  92. domainmap:  
  93.     - name: localhost-to-test  
  94.       source: test.test.cc  
  95.       target: www.bing.cn  
  96.       client_headers:  
  97.         X-Forwarded-For: 192.168.100.1  
  98.       server_headers:  
  99.         X-Forwarded-Proto: http  
  100.       protocol: http  
  101.     - name: 34444  
  102.       source: www.baidu.com  
  103.       target: 96336.ww.com  
  104.       client_headers:  
  105.         ua: 1236545  
  106.       protocol: rtsp                  
  107. reload: 5  
  108. proxygroups:  
  109.   蜀小果:  
  110.     proxies:  
  111.       - name: 服务器1  
  112.         type: socks5  
  113.         server: 1.1.1.1  
  114.         port: 1080  
  115.         udp: true  
  116.       - name: 服务器2  
  117.         type: https  
  118.         server: 8.8.8.8  
  119.         port: 1234  
  120.         # headers:  
  121.         #   Host: "1.3.236.22:443"  
  122.         #   X-T5-Auth: "887766543"  
  123.         #   User-Agent: "baiduboxapp"  
  124.     #     - name: test1  
  125.     #       type: socks5  
  126.     #       server: 192.168.0.151  
  127.     #       port: 7890  
  128.     #       # username: "qist" # 账号  
  129.     #       # password: "123456789" # 密码  
  130.     #     - name: test2  
  131.     #       type: socks4  #认证没实现  
  132.     #       server: 192.168.0.151  
  133.     #       port: 7891  
  134.     #     - name: test2  
  135.     #       type: socks4a  #认证没实现  
  136.     #       server: 192.168.0.151  
  137.     #       port: 7891  
  138.     #     - name: test3  
  139.     #       type: http  
  140.     #       server: 192.168.0.151  
  141.     #       port: 7890  
  142.     #       # username: "qist" # 账号  
  143.     #       # password: "123456789"  # 密码  
  144.     #       # headers: # 代理服务器验证headers 配置  
  145.     #       #   Host: "1.3.236.22:443"  
  146.     #       #   X-T5-Auth: "887766543"  
  147.     #       #   User-Agent: "baiduboxapp"  
  148.     #     # - name: test4  
  149.     #       # type: https  
  150.     #       # server: 78.141.193.27  
  151.     #       # port: 8888  
  152.     #       # username: "qist"  
  153.     #       # password: "123456789"  
  154.     #       # headers: # 代理服务器验证headers 配置  
  155.     #       #   Host: "1.3.236.22:443"  
  156.     #       #   X-T5-Auth: "887766543"  
  157.     #       #   User-Agent: "baiduboxapp"  
  158.     domains: # 支持通配符号*  
  159.       - live2.rxip.sc96655.com  
  160.     interval: 180s # 秒 默认60s 健康检测时间  
  161.     ipv6: false # IPv6开关 true 开启  
  162.     loadbalance: round-robin # 负载均衡方案:round-robin 轮询 fastest 最快的优先  
  163.     max_retries: 3 # 最大重试3次  
  164.     retry_delay: 1s # 重试延迟1秒  
  165.     max_rt: 100ms # 最大响应时间 默认800ms 大于800ms 不参与轮询 如果所有测速大于800ms 参数轮询  
  166.   四川联通:  
  167.     proxies:  
  168.       - name: sclt1  
  169.         type: socks5  
  170.         server: 1.2.3.4  
  171.         port: 1080  
  172.         udp: true  
  173.       - name: sclt2  
  174.         type: socks5  
  175.         server: 4.3.2.1  
  176.         port: 1080  
  177.         udp: true  
  178.     domains: # 支持通配符号*  
  179.       - "*.rrs.169ol.com" # 规则支持ip 192.168.1.1 子网 192.168.1.0/24 域名 *.rrs.169ol.com live2.rxip.sc96655.com ipv6:1234:5678::abcd:ef01/128  
  180.     interval: 180s # 秒 默认60s 健康检测时间  
  181.     ipv6: false # IPv6开关 true 开启  
  182.     loadbalance: round-robin # 负载均衡方案:round-robin 轮询 fastest 最快的优先  
  183.     max_retries: 3 # 最大重试3次  
  184.     retry_delay: 1s # 重试延迟1秒  
  185.     max_rt: 100ms # 最大响应时间 默认800ms 大于800ms 不参与轮询 如果所有测速大于800ms 参数轮询  
  186.   浙江移动:  
  187.     proxies:  
  188.       - name: 浙江移动1  
  189.         type: socks5  
  190.         server: 192.168.100.1  
  191.         port: 8080  
  192.         udp: true  
  193.     domains:  
  194.       - hwltc.tv.cdn.zj.chinamobile.com  
  195.       - 39.134.179.0/24  
  196.       - 39.134.179.185/24  
  197.       - 120.199.224.178/24  
  198.     interval: 180s  
  199.     loadbalance: round-robin  
  200.     max_retries: 3 # 最大重试3次  
  201.     retry_delay: 1s # 重试延迟1秒  
  202.     max_rt: 200ms  
  203.   mpd:  
  204.     proxies:  
  205.       - name: mpd1  
  206.         type: socks5  
  207.         server: 192.168.100.1  
  208.         port: 8888  
  209.     domains:  
  210.       - 1.1.1.1  
  211.       - "edgeware-live.edgeware.tvb.com"  
  212.       - "*.edgeware.tvb.com"  
  213.       - "hki*-edge*.edgeware.tvb.com"  
  214.     interval: 180s  
  215.     loadbalance: fastest  
Nginx 反向代理配置参考
当你在前端放置 Nginx 做 TLS 终端或域名路由时,建议如下配置把请求反代到本地 TVGate:
XML/HTML代码
  1. server {
  2.     listen 80;
  3.     listen 443 ssl http2;
  4.     server_name dl.test.com;
  5.     ssl_certificate     /etc/nginx/ssl/dl.test.com.crt;
  6.     ssl_certificate_key /etc/nginx/ssl/dl.test.com.key;
  7.     proxy_http_version 1.1;
  8.     proxy_set_header   Host $host;
  9.     proxy_set_header   X-Real-IP $remote_addr;
  10.     proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  11.     proxy_set_header   X-Forwarded-Proto $scheme;
  12.     # 特殊情况: 路径以 /http:// 或 /https:// 开头,直接交给后端处理
  13.     location ~ ^/http(s)?:// {
  14.         proxy_pass http://127.0.0.1:8888;
  15.         proxy_set_header Host $host;
  16.     }
  17.     location / {
  18.         proxy_pass http://127.0.0.1:8888;
  19.         proxy_set_header Host $host;
  20.         proxy_buffering off;
  21.         proxy_cache off;
  22.     }
  23. }
注意事项 / 常见问题
安全性:如果将 TVGate 暴露到公网,请务必在前端使用 TLS(NGINX/证书)并限制访问(IP 白名单、HTTP 认证、VPN 等)。
带宽与性能:流媒体转发占用大量上行带宽,请确认宿主机带宽足够。
版权合规:请确保你有权限分发和访问被转发的内容。
端口冲突:如果 8888 被占用,请在配置或启动参数中修改监听端口。
自动重载配置:修改 config.yaml 后观察日志,确认程序已加载新配置。

« 上一篇 | 下一篇 »

发表评论

评论内容 (必填):