User Tools

Site Tools


reverse_proxy:nginx_reverse_proxy:passing_request_headers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

reverse_proxy:nginx_reverse_proxy:passing_request_headers [2025/05/20 16:14] – created peterreverse_proxy:nginx_reverse_proxy:passing_request_headers [2025/05/20 16:18] (current) peter
Line 1: Line 1:
 ====== 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:
 +
 +<code>
 +location /some/path/ {
 +    proxy_set_header Host $host;
 +    proxy_set_header X-Real-IP $remote_addr;
 +    proxy_pass http://localhost:8000;
 +}
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  In this configuration the “Host” field is set to the $host variable.
 +</WRAP>
 +
 +----
 +
 +===== To prevent a header field from being passed to the proxied server =====
 +
 +Set it to an empty string as follows:
 +
 +<code>
 +location /some/path/ {
 +    proxy_set_header Accept-Encoding "";
 +    proxy_pass http://localhost:8000;
 +}
 +</code>
 +
 +----
  
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