来自nginx代理服务器的转发请求标头 [英] Forward request headers from nginx proxy server

查看:735
本文介绍了来自nginx代理服务器的转发请求标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Nginx作为代理来过滤对我的应用程序的请求。在http_geoip_module的帮助下,我正在创建一个国家代码http-header,我想使用headers-more-nginx-module将其作为请求头传递。这是Nginx配置中的位置块:

I'm using Nginx as a proxy to filter requests to my application. With the help of the "http_geoip_module" I'm creating a country code http-header, and I want to pass it as a request header using "headers-more-nginx-module". This is the location block in the Nginx configuration:

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';
}

但这只会在响应中设置标头。我尝试使用more_set_input_headers而不是more_set_headers但是标题甚至没有传递给回复。

But this only sets the header in the response. I tried using "more_set_input_headers" instead of "more_set_headers" but then the header isn't even passed to the response.

我在这里缺少什么?

推荐答案

如果要将变量传递给代理后端,则必须使用代理模块进行设置。

If you want to pass the variable to your proxy backend, you have to set it with the proxy module.

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

现在它被传递到代理后端。

And now it's passed to the proxy backend.

这篇关于来自nginx代理服务器的转发请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆