ngxlocationcapture 删除原本Authorization 添加新的Authorization
在ngx.location.capture中,您可以使用ngx.req.set_header方法来删除原始请求的Authorization头,并添加新的Authorization头。
以下是一个示例代码:
location /proxy {
resolver 8.8.8.8;
set $new_authorization "Bearer your_new_token";
rewrite ^/proxy/(.*)$ /$1 break;
proxy_pass http://backend$request_uri;
proxy_set_header Host $host;
proxy_set_header Authorization $new_authorization;
header_filter_by_lua_block {
ngx.req.clear_header("Authorization");
ngx.req.set_header("Authorization", ngx.var.new_authorization);
}
}
在这个例子中,我们首先定义了一个新的Authorization头,然后使用ngx.req.clear_header方法删除原始请求的Authorization头。接着,使用ngx.req.set_header方法将新的Authorization头添加到请求中。
请根据您的实际需求进行相应的修改
原文地址: https://www.cveoy.top/t/topic/ilAd 著作权归作者所有。请勿转载和采集!