Skip to content

Commit

Permalink
Force django to serve https if its behind a proxy server (RyanNoelk#165)
Browse files Browse the repository at this point in the history
* Force django to serve https if its behind a proxy server

* adding more docs
  • Loading branch information
RyanNoelk authored Mar 14, 2017
1 parent 8e19351 commit 95e99fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'ChangeMe!')

# Force Django to use https headers if its behind a https proxy.
# See: https://docs.djangoproject.com/en/1.10/ref/settings/#secure-proxy-ssl-header
if os.environ.get('HTTP_X_FORWARDED_PROTO', 'False').lower() == 'true':
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

SITE_ID = 1

DATABASES = {
Expand Down
5 changes: 5 additions & 0 deletions env_dev.list
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ DJANGO_SETTINGS_MODULE=base.settings
DJANGO_DEBUG=True
ALLOWED_HOST=''

# If you are serving content behind an HTTPS proxy,
# Set this to `true`.
# See: https://docs.djangoproject.com/en/1.10/ref/settings/#secure-proxy-ssl-header
HTTP_X_FORWARDED_PROTO=false

# Node config
NODE_ENV=dev
NODE_URL=localhost:8080
Expand Down
5 changes: 5 additions & 0 deletions env_stg.list
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ DJANGO_SETTINGS_MODULE=base.settings
DJANGO_DEBUG=False
ALLOWED_HOST=''

# If you are serving content behind an HTTPS proxy,
# Set this to `true`.
# See: https://docs.djangoproject.com/en/1.10/ref/settings/#secure-proxy-ssl-header
HTTP_X_FORWARDED_PROTO=false

# Node config
NODE_ENV=production
NODE_URL=localhost:8080
Expand Down

0 comments on commit 95e99fb

Please sign in to comment.