Nginx – Override/Modify the HTTP Headers

Posted by

Use Cases:

– If you want to modify the header name before it is sent to Upstream.
– If you want to modify the upstream header name before it is sent to Client.

1. Override/Modify the HTTP Client (Requestor) Headers
Client Http Header data can be accessed using $http_ variable

Eg: x-custom-header $http_x_forwarded_for

location /site/page1/ {
proxy_set_header x-custom-header $http_x-forwarded-for;
proxy_pass http://127.0.0.1:8080;
}

2. Override/Modify the HTTP Upstream(App Server Response) Headers
Upstream Http Header data can be accessed using $upstream_http_ variable

Eg: x-custom-header $upstream_http_x_forwarded_for

location /site/page1/ {
proxy_set_header x-custom-header $upstream_http_x-forwarded-for;
proxy_pass http://127.0.0.1:8080;
}

Leave a Reply

Your email address will not be published.