Halo 的 SteamView 插件配置代理时,遇到了两个错误:一个提示只允许 HTTPS,另一个提示目标地址解析到被禁止的地址。后来配置反向代理,又遇到 504;API 通了之后,游戏封面仍然无法显示。

这次改造的目标很明确:不改插件,不影响 SteamDeals 原有代理,只调整现有 Docker、Nginx 和 WireGuard 配置,让 SteamView 正常访问 Steam。

1. 环境

  • Halo:2.27.3,Docker 部署
  • 插件:sailtrack410/plugin-steamview
  • Docker 网络:webnet
  • nginx:博客 HTTPS 入口
  • steam-wireguard:WireGuard 容器,出口到美国
  • steam-tinyproxy:共享 WireGuard 网络命名空间,监听 8888,供 SteamDeals 使用
  • steamdeals:原有 STEAM_PROXY=http://steam-proxy:8888 链路保持不变

SteamView 需要配置 API、Store、Community 三个地址。

2. 问题现象

在 SteamView 设置中填写 steam-proxy:8888,保存时提示:

出站地址仅允许 https: http://steam-proxy:8888

改用 HTTPS 后,测试连接又报:

出站主机解析到被禁止的地址: steam-proxy
服务器内部发生错误,请稍后再试。

配置 Nginx 代理后,接口请求出现 504。接口终于正常后,游戏列表有数据,但封面图片无法加载。

3. 找到原因

3.1 插件配置的不是 HTTP 代理

查看插件源码后发现,三个“代理域名”配置实际用于替换请求的基础 URL,并不是 HTTP 代理参数。

配置纯域名时,插件会去掉端口并自动补上 HTTPS。因此填写:

steam-proxy:8888

实际可能被处理为:

https://steam-proxy

插件的 HTTP Client 也没有设置 .proxy(...),所以它并不会主动使用 tinyproxy。

3.2 tinyproxy 是正向代理,不能直接充当目标站点

tinyproxy 处理的是代理请求,而插件发送的是直接访问目标地址的请求。请求格式不匹配,tinyproxy 会把请求中的 Host 当作目标主机处理,最终无法正常连接。

3.3 HTTPS 校验和 Docker DNS 问题

Halo 对插件配置的地址有 HTTPS 校验。排查 Halo 开源版相关源码后,未发现这条报错对应的全局插件出站 SSRF 拦截;相关 HttpSecurityUtils 用于附件远程下载。

另一个问题是:宿主机访问 Steam 正常,但 Nginx 容器直连时超时。排查发现容器 DNS 解析异常,直接访问 Steam 的链路不可靠。

4. 改造方案

在 WireGuard 容器共享网络命名空间中增加一个 Nginx Gateway,负责访问 Steam 的各个站点。现有博客 Nginx 只负责 HTTPS 接入和路径转发。

Halo SteamView
      │ HTTPS
      ▼
blog.example.com/steam-proxy/{api,store,community}
      │
      ▼
现有 Nginx(TLS + 路径转发)
      │
      ▼
Steam Gateway Nginx
(共享 steam-wireguard 网络命名空间)
      │
      ▼
WireGuard → 美国出口 → Steam

封面图片单独处理:由博客 Nginx 将 CDN 地址改写为博客自身的 /steam-cdn/ 路径,再转发给 Gateway。

改造后:

  • Gateway 不发布端口,不对公网暴露。
  • Gateway 与 WireGuard 共用网络命名空间,出网和 DNS 走该网络环境。
  • 现有 Nginx 的 HTTPS 入口不变。
  • SteamDeals 原有 tinyproxy 配置不变。

5. 配置 Gateway

创建目录:

mkdir -p ~/nginx-steam-gateway
cd ~/nginx-steam-gateway

5.1 Docker Compose

创建 docker-compose.yml:

services:
  steam-gateway:
    image: nginx:1.27-alpine
    container_name: steam-gateway
    network_mode: "container:steam-wireguard"
    volumes:
      - ./steam-gateway.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped

5.2 Nginx 配置

创建 steam-gateway.conf:

server {
    listen 8081;
    location / {
        proxy_pass https://api.steampowered.com;
        proxy_ssl_server_name on;
        proxy_set_header Host api.steampowered.com;
        proxy_set_header Accept-Encoding "";
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_read_timeout 60s;
    }
}

server {
    listen 8082;
    location / {
        proxy_pass https://store.steampowered.com;
        proxy_ssl_server_name on;
        proxy_set_header Host store.steampowered.com;
        proxy_set_header Accept-Encoding "";
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_read_timeout 60s;
    }
}

server {
    listen 8083;
    location / {
        proxy_pass https://steamcommunity.com;
        proxy_ssl_server_name on;
        proxy_set_header Host steamcommunity.com;
        proxy_set_header Accept-Encoding "";
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_read_timeout 60s;
    }
}

server {
    listen 8084;
    location / {
        proxy_pass https://cdn.cloudflare.steamstatic.com;
        proxy_ssl_server_name on;
        proxy_set_header Host cdn.cloudflare.steamstatic.com;
        proxy_set_header Accept-Encoding "";
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_read_timeout 60s;
    }
}

启动:

docker compose up -d
docker restart steam-gateway

Gateway 使用 network_mode: container:steam-wireguard,因此监听端口属于 WireGuard 容器的网络命名空间。现有 webnet 中的服务通过 steam-wireguard 对应的网络地址访问这些端口。

6. 配置现有 Nginx

创建 ~/nginx/conf.d/steam/locations.conf:

location ^~ /steam-proxy/api/ {
    proxy_pass http://steam-wireguard:8081/;
    proxy_http_version 1.1;
    proxy_set_header Host blog.example.com;
    proxy_set_header Accept-Encoding "";
    proxy_read_timeout 60s;
    proxy_connect_timeout 10s;
}

location ^~ /steam-proxy/store/ {
    proxy_pass http://steam-wireguard:8082/;
    proxy_http_version 1.1;
    proxy_set_header Host blog.example.com;
    proxy_set_header Accept-Encoding "";
    proxy_read_timeout 60s;
    proxy_connect_timeout 10s;
}

location ^~ /steam-proxy/community/ {
    proxy_pass http://steam-wireguard:8083/;
    proxy_http_version 1.1;
    proxy_set_header Host blog.example.com;
    proxy_set_header Accept-Encoding "";
    proxy_read_timeout 60s;
    proxy_connect_timeout 10s;
}

location ^~ /steam-cdn/ {
    proxy_pass http://steam-wireguard:8084/;
    proxy_set_header Host blog.example.com;
    proxy_set_header Accept-Encoding "";
    proxy_read_timeout 60s;
    expires 7d;
    add_header Cache-Control "public, max-age=604800";
}

location ^~ /apis/api.steamview.halo.run/v1alpha1/games {
    include /etc/nginx/conf.d/common/proxy.conf;
    proxy_pass http://blog$request_uri;
    proxy_set_header Accept-Encoding "";
    sub_filter_types application/json;
    sub_filter 'https://cdn.cloudflare.steamstatic.com' 'https://blog.example.com/steam-cdn';
    sub_filter_once off;
}

在博客对应的 server {} 块中加入:

include /etc/nginx/conf.d/steam/locations.conf;

检查并重载配置:

docker exec nginx nginx -t && docker exec nginx nginx -s reload

locations.conf 中包含 location,必须在 server 上下文中引入,不能直接放进 http 上下文。注意不要重复定义相同的 location。

7. 修改 SteamView 设置

将插件的三个地址设置为博客域名下的路径:

API:       https://blog.example.com/steam-proxy/api
Store:     https://blog.example.com/steam-proxy/store
Community: https://blog.example.com/steam-proxy/community

8. 处理封面图片

游戏列表数据可以正常返回,但封面仍然加载失败,是因为封面 URL 在 JSON 中返回给浏览器后,由浏览器直接访问 Steam CDN,并不会经过 Halo 后端。

因此,在博客 Nginx 中使用 sub_filter 替换 JSON 中的 CDN 地址:

sub_filter_types application/json;
sub_filter 'https://cdn.cloudflare.steamstatic.com' 'https://blog.example.com/steam-cdn';
sub_filter_once off;

同时需要:

proxy_set_header Accept-Encoding "";

否则上游压缩内容可能无法替换。sub_filter_types application/json; 用于让替换规则处理 JSON 响应。

改写后,浏览器访问博客的 /steam-cdn/ 路径,由 Nginx 转发到 Gateway 的 8084 端口,再访问 CDN。

9. 验证

9.1 验证 WireGuard 出口

docker run --rm --network container:steam-wireguard curlimages/curl -sS -o /dev/null -w 'api: %{http_code}\n' \
  https://api.steampowered.com/ISteamWebAPIUtil/GetServerInfo/v1/

9.2 验证 Gateway

docker run --rm --network webnet curlimages/curl -sS -o /dev/null -w '%{http_code}\n' \
  http://steam-wireguard:8081/ISteamWebAPIUtil/GetServerInfo/v1/

9.3 验证博客入口

curl -sS https://blog.example.com/steam-proxy/api/ISteamWebAPIUtil/GetServerInfo/v1/

curl -sS 'https://blog.example.com/steam-proxy/store/api/appdetails?appids=730&l=schinese' | head -c 200

curl -sS -o /dev/null -w '%{http_code}\n' \
  'https://blog.example.com/steam-proxy/community/profiles/76561198000000000/badges/?l=english'

9.4 验证封面和 JSON 改写

curl -sS -o /dev/null -w 'cover: %{http_code} %{content_type}\n' \
  https://blog.example.com/steam-cdn/steam/apps/730/header.jpg

curl -sS 'https://blog.example.com/apis/api.steamview.halo.run/v1alpha1/games' \
  | grep -o '"coverUrl":"[^"]*"' | head -3

验收结果:API 返回服务器信息,Store 返回游戏详情,Community 返回 200,封面返回 200 image/jpeg,JSON 中的 coverUrl 已改写为博客 CDN 代理路径。

10. 排查中遇到的坑

  1. 插件的“代理域名”是基础 URL 替换,不是 HTTP 代理参数。
  2. 纯域名配置会丢失端口,并自动补 HTTPS。
  3. tinyproxy 是正向代理,不能直接作为插件请求的目标地址。
  4. 宿主机能访问不代表容器能访问,容器 DNS 也需要单独排查。
  5. location 不能放在 Nginx 的 http 上下文中。
  6. include 和手写配置不要重复定义相同的 location。
  7. 修改挂载的 Nginx 配置文件后,需要重载或重启 Nginx,容器不会自动读取文件变化。
  8. sub_filter 处理 JSON 时,需要关闭上游压缩并设置 sub_filter_types application/json;。
  9. 游戏封面由浏览器请求 CDN,单纯代理 Halo API 并不能解决图片访问问题。

11. 维护命令

修改 Gateway 配置后:

cd ~/nginx-steam-gateway
docker compose up -d
docker restart steam-gateway

修改现有 Nginx 配置后:

docker exec nginx nginx -t && docker exec nginx nginx -s reload

排查 Halo 日志:

docker logs --tail 100 halo 2>&1 | grep -iE 'steam|error|exception'

总结

这次问题的关键不是给 Halo 配置一个 HTTP 代理,而是让插件访问的目标地址变成可用的 HTTPS 入口,再由入口将请求转发到 WireGuard 网络中。

最终通过独立的 Gateway 处理 Steam API、Store、Community 和 CDN 请求,保留原有博客 Nginx 和 SteamDeals 代理链路,实现了不改插件、不影响现有服务的改造。