1.ip访问
禁用ip访问 只能对应端口有效
<VirtualHost *:80>
ServerName xx.xx.xx.xx
ServerAlias *
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
<VirtualHost *:8511>
ServerName xx.xx.xx.xx
ServerAlias *
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>

2.非法域名 本地设置host 将ip绑定为服务器ip
禁用方法
在httpd.conf的末尾加上
这种方法还可以防止使用xx.xx.xx.xx直接访问
#禁止所有非法域名
<VirtualHost *:80>
ServerName xx.xx.xx.xx
ServerAlias *
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>

3.允许访问的域名
为其添加配置
<VirtualHost *:80>
ServerAdmin xx@xx.com
DocumentRoot “/home/wwwroot/xx”
ServerName www.xx.com
ServerAlias *.xx.com
ErrorLog “logs/www.xx.com-error_log”
CustomLog “logs/www.xx.com-access_log” common
<Directory “/home/wwwroot/xx”>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

自由转载,转载请注明: 转载自WEB开发笔记 www.chhua.com

本文链接地址: apache2.4 只允许合法域名访问网站 禁止使用ip、非法域名访问 http://www.chhua.com/web-note5616

随机笔记

更多