Nginx and Django Setup Results in Bad Request (400) Error I'm trying to configure Nginx to serve my Django application, but I'm encountering a "Bad Request (400)" error. I've set up my Nginx server block and Django settings as follows:
server {
listen 80;
server_name subdomain.domain.com;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /static/ {
alias /home/diagrjxt/medinote/staticfiles/;
}
location /media/ {
alias /home/diagrjxt/medinote/media/;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/run/medinote.sock;
}
}
DEBUG = False ALLOWED_HOSTS = ['*'] Issue: I've restarted both Gunicorn and Nginx, but I still receive a "Bad Request (400)" error when I try to access the site. There are no errors in the Nginx error log, but the access log shows the following entries:
103.121.239.95 - - [31/Jul/2024:06:22:40 +0000] "GET / HTTP/1.1" 400 154 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/5127.36" "-"
103.119.239.95 - - [31/Jul/2024:06:22:40 +0000] "GET /favicon.ico HTTP/1.1" 400 154 "http://medinote.diagnotech-ai.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
Try to update the ALLOWED_HOSTS
in your Django settings. You provided DEBUG = False ALLOWED_HOSTS = ['*']
which should include your domain name or IP address that you're using to access your site. Using *
is not really recommended. Replace it with your actual domain name or IP address and see if it works.
Let me know for further scrutiny.