Pel*_*leg 53 proxy nginx http-headers
我正在使用Nginx作为代理来过滤对我的应用程序的请求.在"http_geoip_module"的帮助下,我正在创建一个国家代码http-header,我想使用"headers-more-nginx-module"将其作为请求头传递.这是Nginx配置中的位置块:
location / {
proxy_pass http://mysite.com;
proxy_set_header Host http://mysite.com;;
proxy_pass_request_headers on;
more_set_headers 'HTTP_Country-Code: $geoip_country_code';
}
Run Code Online (Sandbox Code Playgroud)
但这只会在响应中设置标头.我尝试使用"more_set_input_headers"而不是"more_set_headers",但是标题甚至没有传递给响应.
我在这里错过了什么?
Fle*_*der 90
如果要将变量传递给代理后端,则必须使用代理模块进行设置.
location / {
proxy_pass http://example.com;
proxy_set_header Host example.com;
proxy_set_header HTTP_Country-Code $geoip_country_code;
proxy_pass_request_headers on;
}
Run Code Online (Sandbox Code Playgroud)
现在它被传递给代理后端.
Pet*_*nna 26
问题是'_'下划线在header属性中无效.如果删除下划线不是一个选项,您可以添加到服务器块:
underscores_in_headers on;
Run Code Online (Sandbox Code Playgroud)
这基本上是@kishorer747对@Fleshgrinder答案的评论的复制和粘贴,解决方案来自:https://serverfault.com/questions/586970/nginx-is-not-forwarding-a-header-value-when-using -proxy通/ 586997#586997
我在这里添加了它,因为在我的情况下,nginx背后的应用程序工作得非常好,但是很快ngix就在我的烧瓶应用程序和客户端之间,我的烧瓶应用程序将不再看到标题.调试需要花费一些时间.