User Tools

Site Tools


reverse_proxy:nginx_reverse_proxy:passing_request_headers

Reverse Proxy - NGINX Reverse Proxy - Passing Request Headers

By default, NGINX modifies two header fields in proxied requests, “Host” and “Connection”, and eliminates the header fields whose values are empty strings.

  • “Host” is set to the value of the $proxy_host variable, and
  • “Connection” is set to close.

To change these settings, as well as modify other header fields, use the proxy_set_header directive.

  • This directive can be specified in a location or higher.
  • It can also be specified in a particular server context or in the http block.

For example:

location /some/path/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://localhost:8000;
}

NOTE: In this configuration the “Host” field is set to the $host variable.


To prevent a header field from being passed to the proxied server

Set it to an empty string as follows:

location /some/path/ {
    proxy_set_header Accept-Encoding "";
    proxy_pass http://localhost:8000;
}

reverse_proxy/nginx_reverse_proxy/passing_request_headers.txt · Last modified: 2025/05/20 16:18 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki