天天看點

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

繼續閱讀