Bad request 400: nginx / gunicorn
I had the same problem and adding ALLOWED_HOSTS = ("yourdomain.com",)
to settings fixed it.
UPDATE: there few other possibilities:
- Nginx (or whatever web server you use) doesn't pass the $host variable to the app
- Host contains underscores
See details: https://blog.anvileight.com/posts/how-to-fix-bad-request-400-in-django/
As I was having the same issue (400 error code when trying to share with vagrant share), I stumble upon this question. The answer and comments are right, as the obvious solution is to set ALLOWED_HOSTS
list, but I was already setting it correctly (I thought).
I can't speak for nginx as I'm running this on apache2, but here's what solved the issue:
Take a look at the
ALLOWED_HOSTS
doc to find what's best for your case.With vagrant, you might find it useful to accept all the vagrantshare.com subdomain, so just add
'.vagrantshare.com'
(notice the dot) to theALLOWED_HOSTS
list.Not sure if it is really necessary, but I changed the modified date of the
wsgi.py
filetouch wsgi.py
As I'm using apache2, I needed to restart the service.
sudo service apache2 restart
And then it worked.