我有一个简单的重定向规则,例如
location = /redirect-me {
return 307 http://localhost:3001/redirect-me;
}
将对 redirect-me
url 进行 POST 调用,我想要做的就是将 post 调用重定向到另一台服务器。
但是我怎样才能将 X-Header 添加到 request header
去 http://localhost:3001/。
我尝试了 add_header
和 proxy_set_header
。add_header
是将标头添加到响应标头而不是请求标头。
location = /redirect-me {
add_header 'X-Header-a' 'cust_info';
proxy_set_header 'X-Header-p' 'cust_info';
return 307 http://localhost:3001/redirect-me;
}
并且 proxy_set_header
没有添加任何东西。
那么如何在使用 307 重定向时向请求添加标头。?
答案 0 :(得分:0)
使用 proxy_pass
指令代替重定向。我提供了以下文档的链接,其中包括设置标题的示例。
location /redirect-me {
proxy_set_header 'X-Header-p' 'cust_info';
proxy_pass http://localhost:3001/redirect-me;
}
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/