V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
vacuitym
V2EX  ›  NGINX

用 nginx 做的 xai 的转发好像一直有问题

  •  
  •   vacuitym · 3 天前 · 615 次点击

    同样的配置 openai 和 claude 就没问题:

    
    location /xai {
        proxy_pass  https://api.x.ai/;
        proxy_ssl_server_name on;
        proxy_set_header Host api.x.ai;
        proxy_set_header Connection '';
        proxy_http_version 1.1;
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off; 
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    
    

    请求:

    https://chat.xxxxx.com/xai/v1/chat/completions

    报错:

    {
        "code": "Some requested entity was not found",
        "error": "No handler found on route. Please double check your URL and consult https://api.x.ai/docs for more information."
    }
    
    4 条回复    2025-02-18 14:47:27 +08:00
    vincentWdp
        1
    vincentWdp  
       3 天前
    xai 也被添加到 proxy_pass 的 host 里去啦, 也就是 nginx 请求了这个 url:

    https://api.x.ai/xai/v1/chat/completions
    vacuitym
        2
    vacuitym  
    OP
       3 天前
    @vincentWdp 不是的,proxy_pass https://api.x.ai/ 只有这个最后没加/才会把 xai 加进去
    vincentWdp
        3
    vincentWdp  
       3 天前
    @vacuitym 抱歉, 我弄错了, 😨
    vacuitym
        4
    vacuitym  
    OP
       2 天前   ❤️ 1
    已 fixed 。
    原因是他转发到了 https://api.x.ai//v1/chat/completions ,v1 前面多了一个/,只需要修改为 location /xai/ 就可以解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1062 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 18:59 · PVG 02:59 · LAX 10:59 · JFK 13:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.