为什么我在访问域时收到 400 Bad Request 错误?

ste*_*han 2 dns nginx

我的网站已经关闭了 2 个月,我基本上已经放弃了解决这个问题,我一直在与 DO 支持人员交谈以及在 stackoverflow 上发帖,但似乎没有人能够帮助我。

设置:Digital Ocean 一键安装django、ubuntu、nginx

问题:设置域后,访问该域会导致 400 错误。访问 IP 没有问题。我使用 Google Domains 购买了域,并使用了自定义名称服务器选项并放置了:

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com
Run Code Online (Sandbox Code Playgroud)

在 etc/nginx/sites-available/django 我有:

upstream app_server { 
server 127.0.0.1:9000 fail_timeout=0; 
}

server { 
listen 80 default_server; 
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html; 
index index.html index.htm;

client_max_body_size 4G; 
server_name cannablr.com www.cannablr.com;

keepalive_timeout 5;

# Your Django project's media files - amend as required 
location /media { 
alias /home/django/django/dealr/dealr/media; 
}

# your Django project's static files - amend as required 
location /static { 
alias /home/django/django/dealr/dealr/static; 
} 

location /favicon.ico { 
alias /home/django/django/dealr/favicon.ico; 
}

location / { 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header Host $http_host; 
proxy_redirect off; 
proxy_pass http://app_server; 
} 
}
Run Code Online (Sandbox Code Playgroud)

我在 etc/nginx/sites-enabled 中符号链接了这个文件。

另一件可能值得注意的事情是,即使我在访问域时收到 400 错误,它仍会加载网站图标。错误日志中没有错误(配置了错误日志)

任何想法或帮助将不胜感激。

big*_*012 5

尝试添加这个ALLOWED_HOSTS = ("yourdomain.com",)

  • 我简直不敢相信就是这样。现在可以用了,非常感谢 (2认同)