将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".您可能需要在ALLOWED_HOSTS中添加"123.56.221.107".
[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".您可能需要将"www.pythonzh.cn"添加到ALLOWED_HOSTS.
Invalid HTTP_HOST header: ‘www.pythonzh.cn’. You may need to add ‘www.pythonzh.cn’ to ALLOWED_HOSTS.
报告于/无效的HTTP_HOST标头:"www.pythonzh.cn".您可能需要将"www.pythonzh.cn"添加到ALLOWED_HOSTS.
Report at / Invalid HTTP_HOST header: ‘www.pythonzh.cn’. You may need to add ‘www.pythonzh.cn’ to ALLOWED_HOSTS.
请求方法:GET请求URL: 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".您可能需要将"pythonzh.cn"添加到ALLOWED_HOSTS.
[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']
我的博客网站www.zmrenwu.com
的Nginx配置:
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屋!