天天看点

Nginx获取自定义头部header的值

在参考了资料:

<a href="http://stackoverflow.com/questions/8393772/how-to-get-non-standard-http-headers-on-nginx" target="_blank">http://stackoverflow.com/questions/8393772/how-to-get-non-standard-http-headers-on-nginx</a>

<a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers" target="_blank">http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers</a>

<a href="http://serverfault.com/questions/297225/nginx-passing-back-custom-header" target="_blank">http://serverfault.com/questions/297225/nginx-passing-back-custom-header</a>

<a href="https://easyengine.io/tutorials/nginx/forwarding-visitors-real-ip/" target="_blank">https://easyengine.io/tutorials/nginx/forwarding-visitors-real-ip/</a>

<a href="http://www.ttlsa.com/nginx/nginx-proxy_set_header/" target="_blank">http://www.ttlsa.com/nginx/nginx-proxy_set_header/</a>

后得到如下:

1、nginx是支持读取非nginx标准的用户自定义header的,但是需要在http或者server下开启header的下划线支持:

underscores_in_headers on;

2、比如我们自定义header为X-Real-IP,通过第二个nginx获取该header时需要这样:

$http_x_real_ip; (一律采用小写,而且前面多了个http_)

3、如果需要把自定义header传递到下一个nginx:

如果是在nginx中自定义采用proxy_set_header X_CUSTOM_HEADER $http_host;

示例:

转自:http://blog.csdn.net/xbynet/article/details/51899286

本文转自奔跑在路上博客51CTO博客,原文链接http://blog.51cto.com/qiangsh/1842944如需转载请自行联系原作者

qianghong000

继续阅读