I am trying to configure nginx along with Gunicorn for a Django project. nginx is giving me the following error:
DisallowedHost at /
Invalid HTTP_HOST header: 'localhost:90,localhost:90'. The domain name provided is not valid according to RFC 1034/1035.
This is my nginx configuration
server {
listen 90;
listen [::]:90;
server_name xxxx;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/djangopro/djangoapp;
}
location / {
include proxy_params;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_buffering off;
proxy_redirect off;
proxy_pass http://localhost:8200/;
}
}
Gunicorn is serving the site properly at localhost:8200
. Can anyone tell me what is causing the error?
I was getting the same error. I'm guessing you might be coming from Flask converting to Django? If you remove the proxy_set_header Host $http_host;
line from your configuration, it should work (it fixed my error). I think what that does is stack together both the requesting ip address, and the proxy ip address, while Django only wants a single ip address, not a list. See this Django ticket: https://code.djangoproject.com/ticket/28028
I'm guessing you already got this figured out (since its been a few months), but I'm still answering to save someone the 2 hours I just spent googling :)
edit: I'd like to clarify, the problem comes from having both include proxy_params;
and proxy_set_header Host $http_host;
set. The default proxy_params
already have the proxy_set_header Host $http_host;
included, so it'll set the host twice, hence the list of two hosts. Look at the proxy_params
file in /etc/nginx/proxy_params
if you're on Ubuntu (will be a similar path on other machines).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With