如何在 nginx 中上游请求之前在 LUA 代码中设置 proxy_http_version [英] How to set proxy_http_version in LUA code before upstreaming the request in nginx
本文介绍了如何在 nginx 中上游请求之前在 LUA 代码中设置 proxy_http_version的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式更改 Lua 代码中的代理 http 版本.有什么办法吗?
I want to change the proxy http version in Lua code programmatically. Is there any way?
是的,我知道我们可以通过位置/服务器块中的 nginx 配置 文件来设置它.有什么办法可以根据请求动态使用 Lua 来实现吗?
Yes, I know that we can set it via the nginx config file in the location/server block. Is there any way that I can do it using Lua dynamically per request?
推荐答案
14.10.2020 更新
location / {
content_by_lua_block {
-- some logic here
if flag then
return ngx.exec("@http1_0")
end
return ngx.exec("@http1_1")
}
}
location @http1_0 {
proxy_pass ...;
proxy_http_version 1.0;
...
}
location @http1_1 {
proxy_pass ...;
proxy_http_version 1.1;
...
}
这篇关于如何在 nginx 中上游请求之前在 LUA 代码中设置 proxy_http_version的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文