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