[关闭]
@dooy 2023-05-30T03:31:21.000000Z 字数 947 阅读 97

chatGPT openai 代理配置

未分类


api.openai.com.conf 配置

  1. server
  2. {
  3. listen 6008;
  4. server_name api.openai.com;
  5. index index.html index.php index.shtml index.htm ;
  6. location / {
  7. #proxy_ssl_protocols TLSv1.2;
  8. proxy_ssl_protocols TLSv1.2 TLSv1.3;
  9. proxy_ssl_server_name on;
  10. proxy_pass https://api.openai.com;
  11. proxy_buffering off;
  12. proxy_set_header Host api.openai.com;
  13. proxy_connect_timeout 12000s;
  14. proxy_read_timeout 12000s;
  15. proxy_send_timeout 12000s;
  16. proxy_buffer_size 512k;
  17. proxy_buffers 4 512k;
  18. break;
  19. }
  20. }

GPT4的回答 不知道是否可以实现

ngx.location.capture 是由 ngx_lua 模块提供的用来发送内部子请求的API。直接使用 Lua 代码对 Nginx 发起子请求并等待响应。

如果您想避免子请求的响应被缓冲而是实时返回,可以考虑使用 ngx.location.capture_multi 函数。

此外,您还需要确保创建一个新的 location,并在其中设置 proxy_buffering off;。具体做法如下:

在 nginx.conf 中配置新的 location
location /realtime {
internal;
proxy_pass http://your_backend_server/;
proxy_buffering off;
}
修改 Lua 代码以使用 ngx.location.capture_multi
lua
location /your_lua_location {
content_by_lua_block {
local resp = ngx.location.capture_multi {
{"/realtime", { args = ngx.req.get_uri_args() }},
}

    -- Handle response here
    ...
}

}

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注