Behind_LB
Behind-LB is a very simple and efficient Django middleware to obtain the client IP address when the project runs behind a trusted load balancer.
It allows to specify the path that activate the middleware, for example / or /a/specific/path. The path must be specified in the variable BEHIND_LB_PATH in your settings.py.
It works with any load balancer that sends the public remote address in a fixed relative position in the header (first, second,… , last). For example, Amazon ELB puts it in the last position, Google Compute Load Balancer in the penultimate one. The position must be specified in settings.BEHIND_LB_POSITION.
Quick start
Install the package:
pip install django-behind-lb
Just add django-behind-lb to your INSTALLED_APPS setting like this:
MIDDLEWARE_CLASSES = ( 'behind_lb.middleware.BehindLB', ...Configure the path and position in settings.py:
BEHIND_LB_PATH = "/" BEHIND_LB_POSITION = -2 # For Google Compute Engine
Try it reading the default request.META['REMOTE_ADDR'] in a View class. It should read the real client IP.
Position options
The BEHIND_LB_PATH value specifies the position of the real IP address in the X-Forwarded-For header, where 0 is the first (or “left”), 1 the second, -2 the penultimate position and -1 the last one. Examples:
BEHIND_LB_POSITION = 0 # First BEHIND_LB_POSITION = -2 # Next to last, for Google Compute Engine LB BEHIND_LB_POSITION = -1 # Last, for Amazon EC2 LB
In Github
The code is available at https://github.com/APSL/django-behind-lb
Metadata
Release files for django-behind-lb 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-behind-lb-1.0.2.tar.gz | 3.0 kB | Without provenance | Details for django-behind-lb-1.0.2.tar.gz |
Release files / django-behind-lb-1.0.2.tar.gz
| Download URL | django-behind-lb-1.0.2.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9995fa77d719bb725fbfb7651b9d5aa15bc8aad45f57a9ac85cbc531836292be
|
|
BLAKE2b-256 checksum How to use checksums |
a8e052017efb7a9d45906a49c613efe52f3efacc60ad92f7b0a48ce16070a6e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-behind-lb 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.