Skip to content

How to add custom trusted_hosts when working with django+nginx+proxy #2917

Closed Answered by davidism
jeromelefeuvre asked this question in Q&A
Discussion options

You must be logged in to vote

Most operating systems are now pre-configured to treat *.localhost as 127.0.0.1. So my strategy for using domains during local development is project.localhost, api.localhost, auth.api.localhost etc. If you use that, everything will already work.

Otherwise, the debugger is implemented as WSGI middleware. I'm not entirely sure how to add WSGI middleware to Django (as opposed to Django middelware), but it's definitely possible.

app = django.get_wsgi_app()  # something like this
debug_app = DebuggedApplication(app, evalex=True)
debug_app.trusted_hosts = [...]   # your own hosts here, or from django config
# somehow tell the django dev server to run this app instead

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jeromelefeuvre
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants