Nginx $proxy_host| $host | $http _host Difference

Source: Internet
Author: User

Proxy_set_headerallows the request header to be redefined or added to the backend server. value can contain text, variables, or combinations of them. When and only if no directives are defined in the current configuration level proxy_set_header , the configuration is inherited from the above level. By default, only two of the request headers are redefined:

Proxy_set_header Host $proxy _host;

Proxy_set_header Connection Close;


Nginx uses IP-based forwarding for upstream by default, so for the following configurations:

Upstream Web {

Server abc.com;

}

server {

Listen 80;

server_name www.hehe.com;


Location/front {

Proxy_pass http://web;

Proxy_set_header Host $proxy _host;

}

}


When matching to/front, using web processing, to upstream to match to ABC.com, where the direct conversion to IP for forwarding. If the abc.com is configured under another nginx, the IP is 10.10.10.10, then the $proxy_host corresponds to 10.10.10.10. This is equivalent to setting the host to 10.10.10.10. If you want host to be a abc.com, make the following settings:

Proxy_set_header Host abc.com;


If you do not want to change the value of the request Header "Host", you can set this:

Proxy_set_header Host $http _host;


However, if the header is not carried in the client request headers, then the request passed to the backend server does not contain this header. In this case, the better way is to use the $host variable-its value is the value of the "Host" field when the request contains the "host" request header, and the primary domain name of the virtual host when the request does not carry the "host" Request header:

Proxy_set_header Host $host;


In addition, the server name can be transferred along with the port of the backend server:

Proxy_set_header Host $host: $proxy _port;


If the value of a request header is null, then the request header will not be routed to the backend server:

Proxy_set_header accept-encoding "";




Nginx $proxy_host| $host | $http _host Difference

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.