Currently in our setup, we are using the X-Real-IP header setting in nginx, to tell in our backend apache logs the IP address of the client. Is it possible to set up nginx to insert an arbitrary HTTP header with text of my choosing, or with it's own IP address? I'd like to set this up for the purposes of doing some easier log analysis. Thanks! Posted at Nginx Forum: http://forum.nginx.org/read.php?2,235827,235827#msg-235827
on 2013-02-01 20:21
on 2013-02-01 20:37
On Fri, Feb 01, 2013 at 02:21:05PM -0500, zacharyalexstern wrote: Hi there, > Currently in our setup, we are using the X-Real-IP header setting in nginx, > to tell in our backend apache logs the IP address of the client. Which line in your nginx configuration is doing that? > Is it possible to set up nginx to insert an arbitrary HTTP header with text > of my choosing, or with it's own IP address? Yes. What happens if you copy the current line, and change some parts of it? It should be straightforward enough to test. f -- Francis Daly francis@daoine.org
on 2013-02-01 20:44
Ah, so, we have this line: proxy_set_header X-Real-IP $remote_addr; Is there a list of the variables similar to $remote_addr somewhere? Is $proxy_host possibly what we need? Posted at Nginx Forum: http://forum.nginx.org/read.php?2,235827,235830#msg-235830
on 2013-02-01 20:53
On Fri, Feb 01, 2013 at 02:44:17PM -0500, zacharyalexstern wrote: > Ah, so, we have this line: > proxy_set_header X-Real-IP $remote_addr; http://nginx.org/r/proxy_set_header for details. > Is there a list of the variables similar to $remote_addr somewhere? http://nginx.org/en/docs/http/ngx_http_core_module... Other modules may provide other variables. > Is $proxy_host possibly what we need? Possibly. It really depends on what you wish to achieve, which I don't think is clear yet from this thread. f -- Francis Daly francis@daoine.org
on 2013-02-01 20:57
I'd like nginx to set a header that contains the IP address of the server nginx is running on. So something like: proxy_set_header X-Nginx-IP $proxy_host; Assuming $proxy_host evaluates to the IP of the server nginx is running on. Posted at Nginx Forum: http://forum.nginx.org/read.php?2,235827,235833#msg-235833
on 2013-02-01 21:41
On Fri, Feb 01, 2013 at 02:57:00PM -0500, zacharyalexstern wrote: > I'd like nginx to set a header that contains the IP address of the server > nginx is running on. There is (almost certainly) not exactly one IP address that fits that description. Maybe $server_addr is adequate? Easiest is probably "proxy_set_header X-Nginx-IP 10.11.12.13;" on the server that you want to identify as 10.11.12.13. But if you wind back to *why* you want that -- apache already knows what ip address the connection to it came from (which should be an address of the server that nginx is running on). It would have logged it, except that you configured apache to discard that address and instead use the content of the X-Real-IP header. Possibly changing the apache configuration to log the content of the X-Real-IP header as well as its client ip address is easiest of all. Whether that is appropriate in your environment depends on what else your apache does with the information. f -- Francis Daly francis@daoine.org
on 2013-02-01 21:47
There are several nodes in between nginx and apache. It's not internet
->
nginx -> apache.
It's internet -> nginx -> varnish -> haproxy - > apache1
- >
apache2
- >
apacheN
So far, everything is in the apache access logs except the IP of the
nginx
server connecting.
But you're right, I could just set it manually, for each nginx server. I
might just do that.
And you're also again right that our servers have multiple IPs.
Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,235827,235837#msg-235837
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.