I have the following server configuration:
Django App - Gunicorn - Nginx
Nginx directs incoming requests to the gunicorn instance. The site can be reached directly, or through redirects from other domains. To clarify:
App is hosted on api.myapp.com
- Some clients directly issue requests to api.myapp.com
- Some clients issue requests to someotherdomain.com, which is also controlled by me. In the nginx config for someotherdomain.com, I forward requests to api.myapp.com with proxy_pass
In this setup, I want to be able to get end users IP address. I have the following directives nginx conf for api.myapp.com
set_real_ip_from my_ip; real_ip_header X-Forwarded-For; real_ip_recursive on; With these directives, X-Real-IP header is set correctly when requests come from redirects, but is is not set at all when requests directly come to api.myapp.com, and I'm kinda confused here. I've tried several other configurations with no success. What can I do to be able to get user's real ip in cases of redirects and directs acccesses?