Bad request 400: nginx / gunicorn Bad request 400: nginx / gunicorn nginx nginx

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:

  1. Nginx (or whatever web server you use) doesn't pass the $host variable to the app
  2. 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:

  1. Take a look at the ALLOWED_HOSTS doc to find what's best for your case.

  2. With vagrant, you might find it useful to accept all the vagrantshare.com subdomain, so just add '.vagrantshare.com' (notice the dot) to the ALLOWED_HOSTS list.

  3. Not sure if it is really necessary, but I changed the modified date of the wsgi.py file

    touch wsgi.py
  4. As I'm using apache2, I needed to restart the service.

    sudo service apache2 restart

And then it worked.