Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

Maxim Dounin mdounin at
Thu Mar 29 13:40:35 UTC 2018


On Wed, Mar 28, 2018 at 04:15:44PM -0400, Ryan Burn wrote:

> > You are not allowed to modify r->headers_in, at any time.
> If I want to ensure that certain headers are added if the request is
> proxied upstream, is there any way to do that?

Recommended approach is to export a variable with the appropriate 
value, and use

    proxy_set_header X-Your-Header $your_variable;

in the configuration.

For example, nginx itself uses this approach with X-Forwarded-For, 
see the $proxy_add_x_forwarded_for variable description here:

Maxim Dounin

More information about the nginx-devel mailing list