Open Hanoboo opened 9 months ago
I don't know if proxy_pass_header helps.
I don't know if proxy_pass_header helps.
It works,but I want to set the header dynamically in lua code.
You should do something like this:
upstream foo {
server 127.0.0.1:6666 weight=1;
}
server {
listen 8001;
set $dynamicConnectionHeader ''; # default value
location / {
rewrite_by_lua_block {
ngx.var.dynamicConnectionHeader = "Upgrade"
}
proxy_pass http://foo;
proxy_set_header Connection $dynamicConnectionHeader;
}
}
server {
listen 8002;
set $dynamicConnectionHeader 'Upgrade'; # default value
location / {
rewrite_by_lua_block {
ngx.var.dynamicConnectionHeader = ""
}
proxy_pass http://foo;
proxy_set_header Connection $dynamicConnectionHeader;
}
}
You should do something like this:
upstream foo { server 127.0.0.1:6666 weight=1; } server { listen 8001; set $dynamicConnectionHeader ''; # default value location / { rewrite_by_lua_block { ngx.var.dynamicConnectionHeader = "Upgrade" } proxy_pass http://foo; proxy_set_header Connection $dynamicConnectionHeader; } } server { listen 8002; set $dynamicConnectionHeader 'Upgrade'; # default value location / { rewrite_by_lua_block { ngx.var.dynamicConnectionHeader = "" } proxy_pass http://foo; proxy_set_header Connection $dynamicConnectionHeader; } }
The request header to be set is obtained dynamically through Lua and cannot be hard-coded with proxy_set_header.
The connection header will be specially processed by nginx proxy (the default header value is "close"). You must use proxy_set_header to set the value of the connection header. You can use Lua to set other headers normally.
Have you solved this problem?I have a similar problem,
Originally posted by @djfsb in https://github.com/openresty/lua-nginx-module/issues/437#issuecomment-948387694