I've the following problem with Nginx and GeoIP and will be nice if you can give me some pointers about the solution.

Note: I know this can be solved on DNS side, but that won't be possible by now so I'm looking for other solution.

The problem
My www.domain.com has IP address located in Amazon running Nginx with a redirect like this:

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

On there's another nginx using geoIP. The problem is that all my clients seems to come from, as 2nd nginx is geolocating by $remote_addr.

Is there any way to catch real client IP ($remote_addr on and pass it as a different variable to and use it on geolocalization?

Any tip, comment or RTFM is welcome. I'll keep looking for a solution to try to answer this question.



On your upstream nginx, use the RealIpModule to get the real IP out of the X-Forwarded-For header that you are sending from your downstream nginx.

For example:

server {
    real_ip_header X-Forwarded-For;
  • Hi Michael, thanks for your help. This solved the issue! – boris quiroz Aug 8 '13 at 19:06

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.