fix(llm): base_url 端口跟随调用方 Host(修正 .11 上打不通的回显地址)
问题:账号态回的 base_url 不带端口(https://lm.mayishangshu.cn/deepseek/v1), 而本网关在宿主 88 上。客户端照它拼请求会落到 443 —— 实测那是**出口 SSL 设备**, 返回 HTTP 200 + 一个 HTML 登录页:状态码正常、内容完全不对,最难察觉的一种失败。 也不能写死 :88:挂在 443 反代后面时又必须不带端口。 改法:新增 http::host_port()(从 Host 头取 ":88"/""),base_url / view / view_all 接收端口参数,调用方从当前请求取。88 部署给 :88,443 反代给无端口,两种都对。 本轮 .11 实机交付验证: - 镜像 ipass-1.0.0(digest 046a9dd7…)更新完成:端口 88:18098、网络 ipass_default、 数据目录 /home/train11/ipass/data 全部复刻,3 账号 / 1 域名 / 1 上游无损;worker 可写。 - 给 deepseek 登记 deepseek-chat / deepseek-reasoner(保存时不提交 auth 字段 → 密钥未被动)。 - 两把 Key 实调真实 DeepSeek 均 200,含此前 404 的 /deepseek/v1/chat/completions(去重修复生效)。 - 用量统计按账号/按模型正确累加;账号态自查可用。 文档:§15 对外端口由 :18098 更正为宿主 :88;§16 新增条目;CLAUDE.md 补 base_url 端口约定。 回归:网关 78 + LLM 77 = 155 条全绿(新增 2 条端口自适应断言)。
This commit is contained in:
1 parent
5e8c38aef4
commit
6a5387b8ce
8 files changed
+94
-30
No files matched your search
+10
-5
@@ -504,7 +504,7 @@ fn h_my_delete(r: *mut ngx_http_request_t, actor: Actor) -> Status {
|
||||
fn h_admin_upstreams(r: *mut ngx_http_request_t, _actor: Actor) -> Status {
|
||||
http::ok(
|
||||
r,
|
||||
json!({ "items": upstreams::view_all(&upstreams::all()) }),
|
||||
json!({ "items": upstreams::view_all(&upstreams::all(), &http::host_port(r)) }),
|
||||
"ok",
|
||||
)
|
||||
}
|
||||
@@ -540,7 +540,8 @@ fn h_admin_upstream_save(r: *mut ngx_http_request_t, _actor: Actor) -> Status {
|
||||
"[api] 保存 LLM 上游 {slot} enabled={enabled} models={}",
|
||||
up.models.len()
|
||||
));
|
||||
http::ok(r, upstreams::view(&slot, &up), "已保存")
|
||||
// base_url 带「调用方正在用的端口」:见 upstreams::base_url 的说明
|
||||
http::ok(r, upstreams::view(&slot, &up, &http::host_port(r)), "已保存")
|
||||
}
|
||||
Err(e) => http::fail(r, HTTPStatus::BAD_REQUEST, &e),
|
||||
}
|
||||
@@ -661,6 +662,8 @@ fn user_or_401(r: *mut ngx_http_request_t, actor: Actor) -> Result<User, Status>
|
||||
/// 刻意只回显 slot / base_url / **模型清单**——**不回显任何密钥**(连脱敏都不给,
|
||||
/// 上游密钥与调用方无关,没有知道的必要)。
|
||||
fn h_my_upstreams(r: *mut ngx_http_request_t, actor: Actor) -> Status {
|
||||
// 回显的 base_url 必须带「调用方正在用的端口」,否则客户端照着拼会打不通
|
||||
let port = http::host_port(r);
|
||||
let user = match user_or_401(r, actor) {
|
||||
Ok(u) => u,
|
||||
Err(e) => return e,
|
||||
@@ -671,7 +674,7 @@ fn h_my_upstreams(r: *mut ngx_http_request_t, actor: Actor) -> Status {
|
||||
.map(|(slot, up)| {
|
||||
json!({
|
||||
"slot": slot,
|
||||
"base_url": upstreams::base_url(&slot, &up),
|
||||
"base_url": upstreams::base_url(&slot, &up, &port),
|
||||
"models": up.models,
|
||||
"note": up.note,
|
||||
})
|
||||
@@ -687,6 +690,8 @@ fn h_my_upstreams(r: *mut ngx_http_request_t, actor: Actor) -> Status {
|
||||
/// (形状 `{object:"list",data:[{id,...}]}`),这边给管理/自研客户端用
|
||||
/// (形状 `{code,msg,data}`,带 base_url 便于直接拼请求)。
|
||||
fn h_my_models(r: *mut ngx_http_request_t, actor: Actor) -> Status {
|
||||
// 同 h_my_upstreams:base_url 跟随调用方所用的端口
|
||||
let port = http::host_port(r);
|
||||
let user = match user_or_401(r, actor) {
|
||||
Ok(u) => u,
|
||||
Err(e) => return e,
|
||||
@@ -699,7 +704,7 @@ fn h_my_models(r: *mut ngx_http_request_t, actor: Actor) -> Status {
|
||||
items.push(json!({
|
||||
"model": model,
|
||||
"slot": slot,
|
||||
"base_url": upstreams::base_url(slot, up),
|
||||
"base_url": upstreams::base_url(slot, up, &port),
|
||||
"note": up.note,
|
||||
}));
|
||||
}
|
||||
@@ -713,7 +718,7 @@ fn h_my_models(r: *mut ngx_http_request_t, actor: Actor) -> Status {
|
||||
.iter()
|
||||
.map(|(slot, up)| json!({
|
||||
"slot": slot,
|
||||
"base_url": upstreams::base_url(slot, up),
|
||||
"base_url": upstreams::base_url(slot, up, &port),
|
||||
"models": up.models,
|
||||
}))
|
||||
.collect::<Vec<_>>(),
|
||||
|
||||
Reference in new issue
Block a user