django-xforwardedfor-middleware | Use the X-Forwarded-For header to get the real ip | REST library
kandi X-RAY | django-xforwardedfor-middleware Summary
kandi X-RAY | django-xforwardedfor-middleware Summary
Use the X-Forwarded-For header to get the real ip of a request
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Parse the request header .
django-xforwardedfor-middleware Key Features
django-xforwardedfor-middleware Examples and Code Snippets
Community Discussions
Trending Discussions on django-xforwardedfor-middleware
QUESTION
I have a load-balanced environment set up in AWS Elastic Beanstalk with a Django app deployed and running Django-user-sessions. I'd like it to be able to log the user session external IP addresses, but everything that gets logged is an internal IP. I have another environment that is not load-balanced and external user IPs are being collected, so I'm fairly sure the user IP is getting overwritten by the internal IP of the load balancer.
I have tried to install django-xforwardedfor-middleware which supposedly adds request.META['REMOTE_ADDR'] = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip()
to each request, but this has not solved the problem.
I also have an HTTPS engine rewrite in my .ebextensions
that is not running on the environment that is working properly, but I don't think it is the problem:
ANSWER
Answered 2019-Jun-21 at 01:08I found the problem: the positioning of x_forwarded_for.middleware.XForwardedForMiddleware
matters. It should come before user_sessions.middleware.SessionMiddleware
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-xforwardedfor-middleware
You can use django-xforwardedfor-middleware like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page