不禁用风险:
1.攻击者可以通过直接访问IP绕过CDN、云WAF等云防护措施
2. 攻击者可以将恶意域名解析至服务器IP地址进行仿站,或导致服务器IP因解析恶意域名被查封。
3. 攻击者可以通过修改host头注入恶意代码至页面当中。
方案:
配置WEB服务器,限制只能通过本地服务器解析的域名访问服务器。
方案一 apache:(亲测)
修改\conf\httpd.conf文件,将如下配置放置在httpd.conf的最后
<VirtualHost *:80> #(*:80 匹配所有)
ServerName 192.168.0.1 #(网站公网IP)
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/chuai" #(资源所在位置)
ServerName www.chuai.com #(网站首页)
</VirtualHost>
重启Apache即可
方案二 nginx:
修改nginx.conf 在目标server添加检测规则,参考以下配置:
(if部分)
server {
server_name 192.168.0.1;(网站公网IP)
listen 8888;
if ($http_Host !~*^192.168.0.1:8888$){
return 403;
}
include /etc/nginx/default.d/*.conf;
location / {
root /www/chuai;
index index.php index.html index.htm;
}
}