[Fixed]-Django get IP only returns 127.0.0.1

27👍

How does get_ip() work?

If nginx is a reverse proxy and gunicorn is the app server, it’s always getting requests from nginx on the local machine.

The real ip that nginx sends to the app server is in my case HTTP_X_REAL_IP via the nginx conf line proxy_set_header X-Real-IP $remote_addr;

So you might want to set that, and in your django app account for the different header by either using your new IP header or set request.META['REMOTE_ADDR'] = request.META['HTTP_X_REAL_IP']

Leave a comment