0

I have a subdomain set up on my site that hosts a Flask application using nginx with the following server configuration. This is hosted on a droplet on DigitalOcean.

server {
    listen 80;
    server_name subdomain.mysite.com;

    location / {
        proxy_pass http://0.0.0.0:8080;
        proxy_redirect http://0.0.0.0:8080 http://subdomain.mysite.com;

    }
}

I am trying to obtain the visitor's IP within my application, but the IP address seems to be the same regardless of visitor. I'm not an expert in this area, so it would be great if someone could explain what was going on, and how I can obtain the real IP address of the visitor.

Sudeep
  • 101
  • 1
  • 1
    Since changing nginx configuration did not work, you need to check how to make Flask application use the IP information passed in HTTP headers instead of the IP address of the TCP socket on the server. – Tero Kilkanen Jul 03 '17 at 19:42

1 Answers1

2

Assuming the IP isn't being changed/translated elsewhere in your network adding the following to your nginx configuration (with the other proxy options) should work

proxy_set_header        X-Real-IP         $remote_addr;
proxy_set_header        X-Forwarded-For   $proxy_add_x_forwarded_for;
Drifter104
  • 3,773
  • 2
  • 25
  • 39