最近,我将我的django网站之一从http升级到https。但是,此后,我一直收到Invalid HTTP_HOST header
错误电子邮件,而从未收到此类电子邮件。
以下是一些日志消息:
奇怪的是,我仅更改了博客站点www.zmrenwu.com
nginx的配置,但似乎托管在123.56.221.107上的所有站点均受到影响。
当然,我正确设置了ALLOWED_HOSTS:
ALLOWED_HOSTS = ['.zmrenwu.com']
ALLOWED_HOSTS = ['.sgsrec.com']
ALLOWED_HOSTS = ['.pythonzh.cn']
我的博客网站
www.zmrenwu.com
的Nginx配置:server {
charset utf-8;
server_name zmrenwu.com www.zmrenwu.com;
listen 80;
return 301 https://www.zmrenwu.com$request_uri;
}
server {
charset utf-8;
server_name zmrenwu.com;
listen 443;
ssl on;
ssl_certificate /etc/ssl/1_www.zmrenwu.com_bundle.crt;
ssl_certificate_key /etc/ssl/2_www.zmrenwu.com.key;
return 301 https://www.zmrenwu.com$request_uri;
}
server {
charset utf-8;
listen 443;
server_name www.zmrenwu.com;
ssl on;
ssl_certificate /etc/ssl/1_www.zmrenwu.com_bundle.crt;
ssl_certificate_key /etc/ssl/2_www.zmrenwu.com.key;
location /static {
alias /home/yangxg/sites/zmrenwu.com/blogproject/static;
}
location /media {
alias /home/yangxg/sites/zmrenwu.com/blogproject/media;
}
location / {
proxy_set_header Host $host;
proxy_pass http://unix:/tmp/zmrenwu.com.socket;
为什么会这样?我该如何解决这个问题?
最佳答案
您需要添加一个块
location / {
}
这种情况(针对非域请求):
if ( $host !~* ^(yourdomain.com|www.yourdomain.com)$ ) {
return 444;
}
和
sudo service nginx reload
关于python - 将Django网站从http升级到https后,我不断收到 `Invalid HTTP_HOST header`错误电子邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47846521/