Merge pull request #2841 from SchrodingersGat/x-forwarded-for

X-forwarded-for
This commit is contained in:
Oliver 2022-04-20 07:02:52 +10:00 committed by GitHub
commit ad541903c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 66 deletions

View File

@ -282,6 +282,7 @@ INSTALLED_APPS = [
MIDDLEWARE = CONFIG.get('middleware', [ MIDDLEWARE = CONFIG.get('middleware', [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'x_forwarded_for.middleware.XForwardedForMiddleware',
'user_sessions.middleware.SessionMiddleware', # db user sessions 'user_sessions.middleware.SessionMiddleware', # db user sessions
'django.middleware.locale.LocaleMiddleware', 'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',

View File

@ -7,9 +7,9 @@ version: "3.8"
# - Serves media and static content directly from Django webserver # - Serves media and static content directly from Django webserver
# IMPORANT NOTE: # IMPORANT NOTE:
# The InvenTree docker image does not clone source code from git. # The InvenTree development image does not clone source code from git.
# Instead, you must specify *where* the source code is located, # Instead, you must specify *where* the source code is located, (on your local machine).
# (on your local machine). # The default setup in this file should work straight out of the box, without modification
# The django server will auto-detect any code changes and reload the server. # The django server will auto-detect any code changes and reload the server.
services: services:

View File

@ -4,24 +4,29 @@ server {
# Listen for connection on (internal) port 80 # Listen for connection on (internal) port 80
listen 80; listen 80;
location / { real_ip_header proxy_protocol;
# Change 'inventree-server' to the name of the inventree server container,
# and '8000' to the INVENTREE_WEB_PORT (if not default) location / {
proxy_pass http://inventree-server:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-By $server_addr:$server_port;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header CLIENT_IP $remote_addr;
proxy_pass_request_headers on;
proxy_redirect off; proxy_redirect off;
client_max_body_size 100M; client_max_body_size 100M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off; proxy_buffering off;
proxy_request_buffering off; proxy_request_buffering off;
# Change 'inventree-server' to the name of the inventree server container,
# and '8000' to the INVENTREE_WEB_PORT (if not default)
proxy_pass http://inventree-server:8000;
} }
# Redirect any requests for static files # Redirect any requests for static files

View File

@ -4,24 +4,30 @@ server {
# Listen for connection on (internal) port 80 # Listen for connection on (internal) port 80
listen 80; listen 80;
location / { real_ip_header proxy_protocol;
# Change 'inventree-dev-server' to the name of the inventree server container,
# and '8000' to the INVENTREE_WEB_PORT (if not default) location / {
proxy_pass http://inventree-dev-server:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-By $server_addr:$server_port;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header CLIENT_IP $remote_addr;
proxy_pass_request_headers on;
proxy_redirect off; proxy_redirect off;
client_max_body_size 100M; client_max_body_size 100M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off; proxy_buffering off;
proxy_request_buffering off; proxy_request_buffering off;
# Change 'inventree-dev-server' to the name of the inventree server container,
# and '8000' to the INVENTREE_WEB_PORT (if not default)
proxy_pass http://inventree-dev-server:8000;
} }
# Redirect any requests for static files # Redirect any requests for static files

View File

@ -22,7 +22,7 @@ django-markdownify==0.8.0 # Markdown rendering
django-markdownx==3.0.1 # Markdown form fields django-markdownx==3.0.1 # Markdown form fields
django-money==1.1 # Django app for currency management django-money==1.1 # Django app for currency management
django-mptt==0.11.0 # Modified Preorder Tree Traversal django-mptt==0.11.0 # Modified Preorder Tree Traversal
django-redis>=5.0.0 django-redis>=5.0.0 # Redis integration
django-q==1.3.4 # Background task scheduling django-q==1.3.4 # Background task scheduling
django-sql-utils==0.5.0 # Advanced query annotation / aggregation django-sql-utils==0.5.0 # Advanced query annotation / aggregation
django-stdimage==5.1.1 # Advanced ImageField management django-stdimage==5.1.1 # Advanced ImageField management
@ -30,6 +30,7 @@ django-test-migrations==1.1.0 # Unit testing for database migrations
django-user-sessions==1.7.1 # user sessions in DB django-user-sessions==1.7.1 # user sessions in DB
django-weasyprint==1.0.1 # django weasyprint integration django-weasyprint==1.0.1 # django weasyprint integration
djangorestframework==3.12.4 # DRF framework djangorestframework==3.12.4 # DRF framework
django-xforwardedfor-middleware==2.0 # IP forwarding metadata
flake8==3.8.3 # PEP checking flake8==3.8.3 # PEP checking
gunicorn>=20.1.0 # Gunicorn web server gunicorn>=20.1.0 # Gunicorn web server
importlib_metadata # Backport for importlib.metadata importlib_metadata # Backport for importlib.metadata