Nginx gets the value of the custom header header

WBOY
Release: 2016-07-28 08:26:48
Original
5763 people have browsed it

Nginx reads custom headers

Reference information:
http://stackoverflow.com/questions/8393772/how-to-get-non-standard-http-headers-on-nginx
http://nginx .org/en/docs/http/ngx_http_core_module.html#underscores_in_headers
http://serverfault.com/questions/297225/nginx-passing-back-custom-header
https://easyengine.io/tutorials/nginx/forwarding -visitors-real-ip/
http://www.ttlsa.com/nginx/nginx-proxy_set_header/
The following is obtained:
1. nginx supports reading non-nginx standard user-defined headers, but it needs to be Enable header underline support under http or server:

  • underscores_in_headers on;

2. For example, if we customize the header to be

$http_x_real_ip; (Always use lower case, and there is an extra http_ in front)
  • 3. If you need to pass the custom header to the next nginx:

If you customize it in nginx, use proxy_set_header X_CUSTOM_HEADER $http_host ;
  • If the header is customized when the user requests it, such as curl –head -H “X_CUSTOM_HEADER: foo” http://domain.com/api/test, you need to pass
  • proxy_pass_header X_CUSTOM_HEADER
  • to pass

    Example:
<span>http</span><span>{</span><span>
    upstream myServer </span><span>{</span><span>        server </span><span>127.0</span><span>.</span><span>0.1</span><span>:</span><span>8082</span><span>;</span><span>}</span><span>
    underscores_in_headers on</span><span>;</span><span>
    server </span><span>{</span><span>
        listen       </span><span>80</span><span>;</span><span>
        server_name  localhost</span><span>;</span><span>        location  </span><span>/</span><span>{</span><span>
  	    proxy_set_header </span><span>Some</span><span>-</span><span>Thing</span><span> $http_x_custom_header</span><span>;;</span><span>
  	    proxy_set_header X</span><span>-</span><span>Forwarded</span><span>-</span><span>For</span><span> $proxy_add_x_forwarded_for</span><span>;</span><span>
  	    proxy_pass http</span><span>://</span><span>myServer</span><span>;</span><span>}</span><span>}</span><span>}</span>
Copy after login

The above introduces Nginx to obtain the value of the custom header, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!