在nginx中将请求上游之前,如何在LUA代码中设置proxy_http_version [英] How to set proxy_http_version in LUA code before upstreaming the request in nginx

查看:146
本文介绍了在nginx中将请求上游之前,如何在LUA代码中设置proxy_http_version的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式在Lua代码中更改代理http版本.有什么办法吗?

I want to change the proxy http version in Lua code programmatically. Is there any way?

是的,我知道我们可以通过location/server块中的 nginx config 文件进行设置.我有什么办法可以根据请求使用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?

推荐答案

已更新2020年10月14日

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆