Apologies if this is answered or documented already but I was confused on this so I'm hoping the community can provide some insight.
The below example is specifically for proxy_pass
and proxy_set_header
config directives, but my overall question is more of a "How does Nginx config handle ordering in general?" type of question.
I came across some working nginx config, with a location block such as this:
location / {
proxy_pass http://internal.example.com/req;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-User $auth_resp_x_user;
}
This confused me since I've always been under the impression that ordering matters, and the headers would need to be set BEFORE the proxy_pass
line. Such as this:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-User $auth_resp_x_user;
proxy_pass http://internal.example.com/req;
}
Questions:
- Does the ordering actually matter?
- If it doesn't matter here, is that specific to proxy_pass? It does matter in other nginx config lines, correct?
- Is this type of ordering/precedence documented anywhere? (Sorry if it is, I'm not seeing it)
Thank you for any insight and help.