将 django 站点从 http 升级到 https 后,我不断收到“无效的 HTTP_HOST 标头"错误电子邮件 [英] I continuously receive `Invalid HTTP_HOST header` error email after I upgrade my django site from http to https
问题描述
最近,我将我的一个 django 站点从 http 升级到 https.但是,在那之后,我不断收到 Invalid HTTP_HOST header
错误电子邮件,而之前我从未收到过此类电子邮件.
Recently, I upgrade one of my django sites from http to https. However, after that, I continuously receive Invalid HTTP_HOST header
error email while before I never received such type of emails.
以下是一些日志消息:
[Django] 错误(外部 IP):无效的 HTTP_HOST 标头:'123.56.221.107'.您可能需要将123.56.221.107"添加到 ALLOWED_HOSTS.
[Django] ERROR (EXTERNAL IP): Invalid HTTP_HOST header: '123.56.221.107'. You may need to add '123.56.221.107' to ALLOWED_HOSTS.
[Django] 错误(外部 IP):无效的 HTTP_HOST 标头:'www.sgsrec.com'.您可能需要将www.sgsrec.com"添加到 ALLOWED_HOSTS.
[Django] ERROR (EXTERNAL IP): Invalid HTTP_HOST header: 'www.sgsrec.com'. You may need to add 'www.sgsrec.com' to ALLOWED_HOSTS.
[Django] 错误(外部 IP):无效的 HTTP_HOST 标头:'sgsrec.com'.您可能需要将sgsrec.com"添加到 ALLOWED_HOSTS.
[Django] ERROR (EXTERNAL IP): Invalid HTTP_HOST header: 'sgsrec.com'. You may need to add 'sgsrec.com' to ALLOWED_HOSTS.
在/apple-app-site-association 报告无效的 HTTP_HOST 标头:‘sgsrec.com’.您可能需要将sgsrec.com"添加到 ALLOWED_HOSTS.
Report at /apple-app-site-association Invalid HTTP_HOST header: ‘sgsrec.com’. You may need to add ‘sgsrec.com’ to ALLOWED_HOSTS.
无效的 HTTP_HOST 标头:‘www.pythonzh.cn’.您可能需要在 ALLOWED_HOSTS 中添加www.pythonzh.cn".
Invalid HTTP_HOST header: ‘www.pythonzh.cn’. You may need to add ‘www.pythonzh.cn’ to ALLOWED_HOSTS.
报告/Invalid HTTP_HOST header: ‘www.pythonzh.cn’.您可能需要在 ALLOWED_HOSTS 中添加www.pythonzh.cn".
Report at / Invalid HTTP_HOST header: ‘www.pythonzh.cn’. You may need to add ‘www.pythonzh.cn’ to ALLOWED_HOSTS.
请求方式:GET 请求地址:http://www.pythonzh.cn/ Django 版本:1.10.6
Request Method: GET Request URL: http://www.pythonzh.cn/ Django Version: 1.10.6
[Django] 错误(外部 IP):无效的 HTTP_HOST 标头:'pythonzh.cn'.您可能需要在 ALLOWED_HOSTS 中添加pythonzh.cn".
[Django] ERROR (EXTERNAL IP): Invalid HTTP_HOST header: 'pythonzh.cn'. You may need to add 'pythonzh.cn' to ALLOWED_HOSTS.
奇怪的是,我只更改了我的博客站点 www.zmrenwu.com
nginx 配置,但似乎所有托管在 123.56.221.107 上的站点都受到影响.强>
What the strange thing is that I only change my blog site www.zmrenwu.com
nginx configuration, but seems all of my sites which hosted on 123.56.221.107 are effected.
当然,我正确设置了 ALLOWED_HOSTS:
Of cause, I set ALLOWED_HOSTS correctly:
ALLOWED_HOSTS = ['.zmrenwu.com']
ALLOWED_HOSTS = ['.sgsrec.com']
ALLOWED_HOSTS = ['.pythonzh.cn']
我的博客站点的Nginx配置www.zmrenwu.com
:
Nginx configuration of my blog site www.zmrenwu.com
:
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;
为什么会这样?我该如何解决这个问题?
Why that happened? And How could I solve this issue?
推荐答案
需要在块中添加
location / {
}
此条件(对于非您的域请求):
this condition (for not-yourdomain request):
if ( $host !~* ^(yourdomain.com|www.yourdomain.com)$ ) {
return 444;
}
和
sudo service nginx reload
这篇关于将 django 站点从 http 升级到 https 后,我不断收到“无效的 HTTP_HOST 标头"错误电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!