Considerations when customizing HTTP headers

Source: Internet
Author: User

Original: https://blog.gnuers.org/?p=462

An HTTP header can contain an English letter ([a-za-z]), a number ([0-9]), a connection number (-) hyphens, or an underscore (_). You should avoid using an underlined HTTP header when using Nginx. The main reasons are the following 2 points.
1. By default, Nginx cannot use an underlined variable when referencing a header variable. To resolve such problems, you can only configure underscores_in_headers on separately.
2. By default, the underlined variable is ignored. To resolve this need to configure ignore_invalid_headers off.

Of course, Nginx set the variable when there is no such restrictions, you can directly set the underlined header. But it is best not to do so. In the use of Nginx multi-level agent, also need to pay attention to some headers do not repeat settings. For example, to save the user's IP header only in the top of the Nginx configuration on the line, the following nginx do not repeat settings resulting in coverage.

Simple test a number of Nginx agent when the idea of processing, in order to facilitate my directly on a nginx run multiple server tests

Worker_processes1; events {Worker_connections1024x768;}    HTTP {include mime.types; Default_type Application/octet-stream; Log_format Main'$http _orig_client_ip-$remote _addr-$remote _user [$time _local] "$request"'                      '$status $body _bytes_sent "$http _referer"'                      '"$http _user_agent" "$http _x_forwarded_for" "$upstream _addr"';    Sendfile on;    Underscores_in_headers on;    Ignore_invalid_headers off; Keepalive_timeout $; upstream test2081{server10.209.128.28:2081;} Upstream test2082{Server10.209.128.28:2082;} Upstream test2083{Server10.209.128.28: the;} server {Listen2080;        server_name localhost; Access_log logs/Access80.log Main; Location/{root HTML;            Proxy_set_header orig_client_ip $remote _addr;            Proxy_set_header Host $http _host; Proxy_set_header X-forwarded-by $server _addr: $server _port; Proxy_set_header X-forwarded-For $http _x_forwarded_for; Proxy_pass http://test2081;}} server {Listen2081;        server_name localhost; Access_log logs/Access81.log Main; Location/{root HTML;            Proxy_set_header Host $http _host; Proxy_set_header X-forwarded-by $server _addr: $server _port; Proxy_set_header X-forwarded-For $http _x_forwarded_for; Proxy_pass http://test2082;}} server {Listen2082;        server_name localhost; Access_log logs/Access82.log Main; Location/{root HTML;            Proxy_set_header Host $http _host; Proxy_set_header X-forwarded-by $server _addr: $server _port; Proxy_set_header X-forwarded-For $http _x_forwarded_for; Proxy_pass http://test2083;        }    }}

When server 2080 receives the request, it sets an irregular HTTP header, which is followed by a 2-segment server connection. After the request is initiated, the log is as follows

You can see that both 2081 and 2082 are able to pass the header correctly (including the 80 port on the machine)

Considerations when customizing HTTP headers (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.