TVGate — IPTV 转发 / 代理工具
功能
转发
将内网可访问的资源(如 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代码
- 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代码
- 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代码
- docker run -d --name=tvgate -p 8888:8888 --restart=unless-stopped -v /usr/local/TVGate/:/etc/tvgate/ juestnow/tvgate:latest
udp转发:
XML/HTML代码
- 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代码
- version: "3"
- services:
- tvgate:
- image: ghcr.io/qist/tvgate:latest # 或 juestnow/tvgate:latest #不能下载 可以换成 67686372.boown.com/qist/tvgate:latest
- container_name: tvgate
- restart: always
- ports:
- - "8888:8888"
- volumes:
- - /usr/local/TVGate/:/etc/tvgate/
运行后可通过 http://宿主机IP:8888/ 访问。
服务管理 / 启动脚本
systemd (Linux)
把以下文件保存为 /etc/systemd/system/TVGate.service:
XML/HTML代码
- [Unit]
- Description=TVGate - IPTV 转发 / 代理工具
- After=network.target
- [Service]
- Type=simple
- LimitCORE=infinity
- LimitNOFILE=100000
- LimitNPROC=100000
- ExecStart=/usr/local/TVGate/TVGate-linux-amd64 -config=/usr/local/TVGate/config.yaml
- Restart=on-failure
- PrivateTmp=true
- ExecReload=/bin/kill -SIGHUP $MAINPID
- [Install]
- WantedBy=multi-user.target
启用并启动:
XML/HTML代码
- systemctl daemon-reload
- systemctl enable --now TVGate
OpenWrt init 脚本(示例)
保存为 /etc/init.d/TVGate 并赋予可执行权限:
XML/HTML代码
- #!/bin/sh /etc/rc.common
- START=99
- STOP=15
- USE_PROCD=1
- PROG=/apps/TVGate/TVGate-linux-arm64
- start_service() {
- procd_open_instance
- procd_set_param command $PROG -config=/apps/TVGate/config.yaml
- procd_set_param respawn
- procd_close_instance
- }
- stop_service() {
- procd_kill $PROG || true
- }
代理规则格式
支持 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代码
- server:
- #监听端口
- port: 8888
- # 证书路径
- certfile: ""
- # 密钥路径
- keyfile: ""
- # SSL 协议版本 (空为默认 TLSv1.2~1.3)
- ssl_protocols: "TLSv1.2 TLSv1.3"
- # SSL 加密套件 (空为默认安全套件)
- 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"
- # SSL ECDH 曲线 (支持 ML-KEM)
- ssl_ecdh_curve: "X25519MLKEM768:X25519:P-384:P-256"
- # 组播监听地址
- multicast_ifaces: [] # 可留空表示默认接口 [ "eth0", "eth1" ]
- # github 加速配置 更新可以用到
- github:
- enabled: false
- url: https://hk.gh-proxy.com
- timeout: 10s
- retry: 3
- backup_urls:
- - https://github.dpik.top
- - https://gitproxy.127731.xyz
- # 监控配置
- monitor:
- path: "/status" # 状态信息
- # 配置文件编辑接口
- web:
- enabled: true
- username: admin
- password: admin
- path: /web/ # 自定义路径
- # 日志输出配置
- log:
- # 是否输出日志
- enabled: true
- # 日志输出文件地址 "" 表示标准输出,否则输出到指定文件 ./access.log
- file: ""
- # 日志大小M单位
- maxsize: 10
- # 压缩文件备份个数
- maxbackups: 10
- # 日志保留天数
- maxage: 28
- # 是否压缩
- compress: true
- http:
- timeout: 0s # 整个请求超时时间 (0 表示不限制)
- connect_timeout: 10s # 建立连接的超时时间
- keepalive: 10s # 长连接的保活时间
- response_header_timeout: 10s # 接收响应头的超时时间
- idle_conn_timeout: 5s # 空闲连接在连接池中的保留时间
- tls_handshake_timeout: 10s # TLS 握手超时时间
- expect_continue_timeout: 1s # Expect: 100-continue 的等待超时时间
- max_idle_conns: 100 # 最大空闲连接数(全局)
- max_idle_conns_per_host: 4 # 每个主机最大空闲连接数
- max_conns_per_host: 8 # 每个主机最大连接数(总数,含空闲和活跃)
- disable_keepalives: false # 是否禁用长连接复用 (false 表示启用 KeepAlive)
- # 10 万并发参考
- # http:
- # timeout: 0s # 整体请求超时,不限制(由上层逻辑控制超时)
- # connect_timeout: 3s # 建立连接的超时时间(越短越好,失败快速切换)
- # keepalive: 30s # 长连接保活时间,保证高并发时连接复用
- # response_header_timeout: 5s # 响应头超时,避免服务端卡死
- # idle_conn_timeout: 90s # 空闲连接保留时间,过短会频繁建连,过长会浪费 FD
- # tls_handshake_timeout: 5s # TLS 握手超时,CDN/直播源一般很快
- # expect_continue_timeout: 1s # 基本不用,保持默认
- # max_idle_conns: 200000 # 全局最大空闲连接数(10 万并发需要翻倍冗余)
- # max_idle_conns_per_host: 10000 # 单 host 的空闲连接上限,保证热点源站可复用
- # max_conns_per_host: 20000 # 单 host 总连接数上限(活跃+空闲),防止热点源阻塞
- # disable_keepalives: false # 必须启用长连接,否则 10 万并发会把源站打爆
- # 配置文件重新加载时间(秒)
- # jx 视频解析接口配置 支持 某奇 某果 某讯 某尤 某咕
- jx:
- path: "/jx" # jx 接口路径,可自定义,例如 /jx
- default_id: "1" # 默认集数,如果请求未传 id,则使用此值
- # 多个视频 API 组配置,可以配置不同的视频源
- api_groups:
- other_api:
- endpoints:
- - "http://23.224.101.30" # 主 API 地址
- - "https://mozhuazy.com" # 备用 API 地址
- timeout: 10s # 请求超时
- query_template: "%s/api.php/provide/vod/?ac=detail&wd=%s" # 查询 URL 模板,%s 会被替换为 endpoint 和搜索关键词
- primary: true # 是否主 API
- weight: 2 # 权重,用于负载均衡
- fallback: true # 是否可以作为备用 API
- max_retries: 3 # 请求失败重试次数
- filters:
- exclude: "电影解说,完美世界剧场版" # 排除包含指定关键字的视频
- domainmap:
- - name: localhost-to-test
- source: test.test.cc
- target: www.bing.cn
- client_headers:
- X-Forwarded-For: 192.168.100.1
- server_headers:
- X-Forwarded-Proto: http
- protocol: http
- - name: 34444
- source: www.baidu.com
- target: 96336.ww.com
- client_headers:
- ua: 1236545
- protocol: rtsp
- reload: 5
- proxygroups:
- 蜀小果:
- proxies:
- - name: 服务器1
- type: socks5
- server: 1.1.1.1
- port: 1080
- udp: true
- - name: 服务器2
- type: https
- server: 8.8.8.8
- port: 1234
- # headers:
- # Host: "1.3.236.22:443"
- # X-T5-Auth: "887766543"
- # User-Agent: "baiduboxapp"
- # - name: test1
- # type: socks5
- # server: 192.168.0.151
- # port: 7890
- # # username: "qist" # 账号
- # # password: "123456789" # 密码
- # - name: test2
- # type: socks4 #认证没实现
- # server: 192.168.0.151
- # port: 7891
- # - name: test2
- # type: socks4a #认证没实现
- # server: 192.168.0.151
- # port: 7891
- # - name: test3
- # type: http
- # server: 192.168.0.151
- # port: 7890
- # # username: "qist" # 账号
- # # password: "123456789" # 密码
- # # headers: # 代理服务器验证headers 配置
- # # Host: "1.3.236.22:443"
- # # X-T5-Auth: "887766543"
- # # User-Agent: "baiduboxapp"
- # # - name: test4
- # # type: https
- # # server: 78.141.193.27
- # # port: 8888
- # # username: "qist"
- # # password: "123456789"
- # # headers: # 代理服务器验证headers 配置
- # # Host: "1.3.236.22:443"
- # # X-T5-Auth: "887766543"
- # # User-Agent: "baiduboxapp"
- domains: # 支持通配符号*
- - live2.rxip.sc96655.com
- interval: 180s # 秒 默认60s 健康检测时间
- ipv6: false # IPv6开关 true 开启
- loadbalance: round-robin # 负载均衡方案:round-robin 轮询 fastest 最快的优先
- max_retries: 3 # 最大重试3次
- retry_delay: 1s # 重试延迟1秒
- max_rt: 100ms # 最大响应时间 默认800ms 大于800ms 不参与轮询 如果所有测速大于800ms 参数轮询
- 四川联通:
- proxies:
- - name: sclt1
- type: socks5
- server: 1.2.3.4
- port: 1080
- udp: true
- - name: sclt2
- type: socks5
- server: 4.3.2.1
- port: 1080
- udp: true
- domains: # 支持通配符号*
- - "*.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
- interval: 180s # 秒 默认60s 健康检测时间
- ipv6: false # IPv6开关 true 开启
- loadbalance: round-robin # 负载均衡方案:round-robin 轮询 fastest 最快的优先
- max_retries: 3 # 最大重试3次
- retry_delay: 1s # 重试延迟1秒
- max_rt: 100ms # 最大响应时间 默认800ms 大于800ms 不参与轮询 如果所有测速大于800ms 参数轮询
- 浙江移动:
- proxies:
- - name: 浙江移动1
- type: socks5
- server: 192.168.100.1
- port: 8080
- udp: true
- domains:
- - hwltc.tv.cdn.zj.chinamobile.com
- - 39.134.179.0/24
- - 39.134.179.185/24
- - 120.199.224.178/24
- interval: 180s
- loadbalance: round-robin
- max_retries: 3 # 最大重试3次
- retry_delay: 1s # 重试延迟1秒
- max_rt: 200ms
- mpd:
- proxies:
- - name: mpd1
- type: socks5
- server: 192.168.100.1
- port: 8888
- domains:
- - 1.1.1.1
- - "edgeware-live.edgeware.tvb.com"
- - "*.edgeware.tvb.com"
- - "hki*-edge*.edgeware.tvb.com"
- interval: 180s
- loadbalance: fastest
Nginx 反向代理配置参考
当你在前端放置 Nginx 做 TLS 终端或域名路由时,建议如下配置把请求反代到本地 TVGate:
XML/HTML代码
- server {
- listen 80;
- listen 443 ssl http2;
- server_name dl.test.com;
- ssl_certificate /etc/nginx/ssl/dl.test.com.crt;
- ssl_certificate_key /etc/nginx/ssl/dl.test.com.key;
- 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;
- # 特殊情况: 路径以 /http:// 或 /https:// 开头,直接交给后端处理
- location ~ ^/http(s)?:// {
- proxy_pass http://127.0.0.1:8888;
- proxy_set_header Host $host;
- }
- location / {
- proxy_pass http://127.0.0.1:8888;
- proxy_set_header Host $host;
- proxy_buffering off;
- proxy_cache off;
- }
- }
注意事项 / 常见问题
安全性:如果将 TVGate 暴露到公网,请务必在前端使用 TLS(NGINX/证书)并限制访问(IP 白名单、HTTP 认证、VPN 等)。
带宽与性能:流媒体转发占用大量上行带宽,请确认宿主机带宽足够。
版权合规:请确保你有权限分发和访问被转发的内容。
端口冲突:如果 8888 被占用,请在配置或启动参数中修改监听端口。
自动重载配置:修改 config.yaml 后观察日志,确认程序已加载新配置。

