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

请教:想通过服务器上的 nginx 做代理转发,访问 gpt3.5 的接口,但是一直 502 或者 504

  •  
  •   bain1wang · 360 天前 · 920 次点击
    这是一个创建于 360 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想做个域名跳板转发,比如访问 example.com 能通过 nginx 转发到 api.openai.com 上去,后面的接口保持不变,只是借助服务器可以翻墙的便利。但是执行过程中一直出错,请问下可能是什么原因。
    nginx 的配置很简单:类似如下
    location /vl/chat/completions {
    proxy pass https://api.openai.com/v1/chat/completions
    }
    location
    9 条回复    2023-05-28 18:31:57 +08:00
    andyskaura
        1
    andyskaura  
       360 天前
    你的 header 呢?Bearer key 也要代理过去
    bain1wang
        2
    bain1wang  
    OP
       360 天前
    @andyskaura 感谢大佬,我试试,应该是这个
    bingNew
        3
    bingNew  
       360 天前
    成功了吗?完整的贴出来看看
    skiy
        4
    skiy  
       360 天前 via iPhone
    用 cloudflare workers 啊…

    https://github.com/devdoz/worker-cdn
    skiy
        5
    skiy  
       360 天前 via iPhone
    另外, /vl/chat/completions ,是 v1 ,不是 vl
    asdjgfr
        6
    asdjgfr  
       360 天前
    同样好奇,我现在用的是一个 golang 写的转发程序,想知道 nginx 可行不?
    collinmehle
        7
    collinmehle  
       360 天前
    #PROXY-START/

    location ^~ /
    {
    proxy_pass https://api.openai.com;
    proxy_set_header Host api.openai.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;

    #Persistent connection related configuration

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache


    set $static_filee3LUvqQR 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
    set $static_filee3LUvqQR 1;
    expires 12h;
    }
    if ( $static_filee3LUvqQR = 0 )
    {
    add_header Cache-Control no-cache;
    }
    }

    #PROXY-END/


    这是宝塔给我配置的片段
    Aibitk
        8
    Aibitk  
       359 天前
    加上这两行,没有强制打开 SSL 及指定协议,导致 SSL 握手失败,在反代的配置里打开,就正常了
    ```
    proxy_ssl_server_name on;
    proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ```
    gotosre
        9
    gotosre  
       327 天前
    印象中, auth 头透传的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2833 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 11:50 · PVG 19:50 · LAX 04:50 · JFK 07:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.