1

I am using a loadbalancer in my current setup, requests come from ip 10.71.128.13.

I am using Nginx as a front to a Gunicorn backend. I want to get the real IP address of the visitor and log it (not the loadbalancer IP).

My nginx.conf:

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

# GET REAL IP
set_real_ip_from   10.71.128.12;
set_real_ip_from   10.71.128.13;
set_real_ip_from   10.71.128.14;
real_ip_header     X-Forwarded-For;

My server block 'example.conf'

# HTTPS
server {

   etc....

location / {

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header X-Forwarded-Proto https;

    proxy_set_header Host $http_host;

    proxy_redirect off;

    proxy_buffering on;
}
}

An example log entry:

10.71.128.13 - - [10/Jun/2014:13:27:58 +0100] "POST /example/ HTTP/1.1" 200 25 "https://example.com/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"

Sadly this configuration just returns the loadbalance IP and not the visitor's IP address... Can anyone help?

Thanks

  • Is this an AWS loadbalancer? If not, what is it? The web server is quite correctly logging at the moment, so the only ways to fix it are either to get a load-balancer that routes rather than proxies the client requests, or to get the load-balancer to send the client IP as an additional datum that the server might be told to log - and to do the latter we need to know what kind of LB it is. – MadHatter Jun 10 '14 at 12:39
  • It's an OVH loadbalancer... This configuration works with just a simple HTTP server and I can get the correct IP. But when using upstream (socket to connect to gunicorn) it seems to break... – Daniel Pilch Jun 10 '14 at 12:44
0

When you have SSL pass-through loadbalancing the proxy can't add the required headers so you'll never know the originating IP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.