Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#573 closed defect (worksforme)

Reloading config with differently cased proxy_set_header field name does not change field name in proxied request

Reported by: Oliver Friedrich Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.5.x
Keywords: Cc:
uname -a: Linux o071.orange.fastwebserver.de 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.5.2

Description

Today, I was pulling my hair out because I wanted to change my wrong X-Forwarded-For configuration from

proxy_set_header    X_FORWARDED_FOR    $proxy_add_x_forwarded_for;

to the correct version

proxy_set_header    X-Forwarded-For    $proxy_add_x_forwarded_for;

I tried reloading the config using service nginx relaod a few times but without success.

The solution that finally worked was to comment the above line completely, reload the configuration, uncomment the corrected version and reload again. Now, the rewritten requests contain the X-Forwarded-For header instead of the wrong X_FORWARDED_FOR one.

Since I don't know nginx's source I cannot tell what scope this problem has - it might be a larger problem, altogether.

Change History (8)

comment:1 by Maxim Dounin, 10 years ago

Resolution: worksforme
Status: newclosed

There are multiple reasons why a configuration reload can fail, and many of them transient. Try looking into error log to find out what happened in your particular case. Note well that "relaod" isn't correct, "reload" is. Note also that nginx 1.5.2 is long time obsolete, current version is 1.7.1.

comment:2 by Oliver Friedrich, 10 years ago

Thanks, Maxim, you were of course right. I work with NGINX only rarely and checking the error.log file I found out that I had been missing a semicolon all the time so the configuration was never actually applied.

The response by service nginx reload is misleading in this case: nginx neu laden: [ OK ] (on a German system). It would help if the status message indicated that the configuration is erronous (but this maybe fixed in newer versions, so I'll update asap).

comment:3 by Maxim Dounin, 10 years ago

The service command isn't part of nginx but rather your OS (or, rather, it calls a script provided by an nginx package you use), and it merely sends the HUP signal to nginx to initiate a configuration reload. Waiting for actual configuration reload results is certainly out of scope of this action though. Moreover, such waiting can't be easily automated as actual reload of a configuration may take very long time, especially including graceful shutdown of old worker processes. And in many cases there is no need to wait for previous reload to complete before doing another one.

To check if a configuration is correct, consider using nginx -t. Many control scripts provide a configtest target for this.

comment:4 by Oliver Friedrich, 10 years ago

Even though I was aware that service is part of the OS, I wasn't aware of the fact that it would not return the underlying service's response. Thanks for clearing this up and for the hint to nginx -t.

To reload nginx, nginx -s reload will be my choice from now on.

comment:5 by Maxim Dounin, 10 years ago

The nginx -s reload is a wrong choice. The only difference is extra parsing of a configuration, and a pid file used from the configuration. Both actions may be incorrect in some cases (e.g., if you are in the middle of an upgrade, and nginx binary on disk differs from one in memory; or you've changed pid file location) and still doesn't cover various errors not related to a configuration parsing (e.g., a configuration reload can fail due to a listen socket being busy). The -s option exists mainly for win32 hosts, where there are no easy way to send signals.

The only correct approach is to look into logs and/or processes to ensure the reload went fine.

comment:6 by Oliver Friedrich, 10 years ago

Thanks for clearing this up. So I understand correctly that service nginx reload should be used for configuration reload, possibly after verifying with nginx -t that the configuration is valid?

I appreciate your patience and help with understanding nginx better!

comment:7 by Maxim Dounin, 10 years ago

Yes. And after doing a configuration reload, you should look into logs to make sure a reload went fine.

comment:8 by Oliver Friedrich, 10 years ago

Doing that every time now. Thanks.

Note: See TracTickets for help on using tickets.