How to set proxy_http_version in LUA code before upstreaming the request in nginx

北城余情 提交于 2020-12-26 12:14:40

问题


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

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?


回答1:


Updated 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;
   ...
}


来源:https://stackoverflow.com/questions/64301671/how-to-set-proxy-http-version-in-lua-code-before-upstreaming-the-request-in-ngin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!