I am trying to start my server with Django, nginx and gunicorn. Everything went well on the development server. But on the production server, the machine gun always returns “Bad Request” (400).
I know that I need to set a variable ALLOWED_HOSTS, and I did it. I tried the correct domain, asterisk, or even set DEBUG to True. But still, it is always Bad Request (400).
Here is my nginx-config:
server {
listen 80;
location /static {
alias /home/username/sites/sub.domain.example.com/static;
}
location / {
proxy_set_header Host $http_host;
proxy_pass http://localhost:8000;
}
}
My wsgi-prod.pyfile:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings_prod")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
File settings_prod.py(shortened):
DEBUG = False
ALLOWED_HOSTS=["*"]
I start shooting as follows (with virtualenv):
gunicorn --bind 127.0.0.1:8000 app.wsgi_prod:application
When I start the server from manage.py runserver --settings=app.settings_prod, the site is accessible. the gunicorn error log shows nothing, and only 400 is displayed in the access log. Static content really works.