@dooy
2023-05-30T03:31:21.000000Z
字数 947
阅读 97
未分类
server
{
listen 6008;
server_name api.openai.com;
index index.html index.php index.shtml index.htm ;
location / {
#proxy_ssl_protocols TLSv1.2;
proxy_ssl_protocols TLSv1.2 TLSv1.3;
proxy_ssl_server_name on;
proxy_pass https://api.openai.com;
proxy_buffering off;
proxy_set_header Host api.openai.com;
proxy_connect_timeout 12000s;
proxy_read_timeout 12000s;
proxy_send_timeout 12000s;
proxy_buffer_size 512k;
proxy_buffers 4 512k;
break;
}
}
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
...
}
}