如何在 nginx 的 upstream 请求中以 Lua 代码方式设置 proxy_http_version

我想在 Lua 代码中以编程方式更改代理 http 版本。有没有办法?

是的,我知道可以通过 nginx 配置 文件在 location/server 块中设置它。但是否有一种方式可以使用 Lua 动态地为每个请求执行此操作?

点赞
用户2060502
用户2060502

更新于2020年10月14日

location / {
   content_by_lua_block {
       -- 在此处添加一些逻辑
       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;
   ...
}
2020-10-13 07:58:35