标签:pre 域名 lan strong wal local root ESS 地址
Apache访问控制1.控制对网站资源的访问
2.为特定的网站目录添加访问授权
1.客户机地址限制
2.用户授权限制
1.使用Require配置项实现访问控制,按先后顺序限制
2.可用于<Location>、 <Directory>、 <Files>、 <Limit>配置段中
Require all granted
Require all denied
Require local
Require [not] host <主机名或域名列表>
Require [not] ip <IP地址或网段列表>
使用not禁止访问时要将其置于<RequireAll> </RequireAll>容器中并在容器中指定相应的限制策略
1.先查看客户机的IP地址
2.配置httpd扩展配置文件
[root@localhost ~]# cd /etc/httpd/conf/extra //扩展配置文件目录
[root@localhost extra]# ls
vhost.conf
[root@localhost extra]# vim vhost.conf //编辑虚拟主机配文件
<VirtualHost 192.168.235.129:80>
DocumentRoot "/var/www/html/accp/"
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_1og" common
<Directory "/var/www/html/">
<RequireAll> //容器起始标签
Require not ip 192.168.235.140 //禁止IP为192.168.235.140的主机访问
Require all granted
</RequireAll> //容器结束标签
</Directory>
</VirtualHost>
[root@localhost extra]# systemctl restart httpd //重启服务
[root@localhost ~]# systemctl restart named
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
3.使用客户机测试网页
1.创建用户认证数据库
[root@localhost ~]# cd /etc/httpd/conf //进入httpd主配置文件
[root@localhost conf]# htpasswd -c /etc/httpd/conf/pwd test //创建用户加密文件,若文件存在则不需要加-c
New password: //输入自定义密码
Re-type new password: //确认密码输入
Adding password for user test
[root@localhost conf]# cat pwd //查看用户及密码加密
test:$apr1$VBfoRWHC$Feck.BITMYhaOlEKrc/1j.
2.配置域名解析
[root@localhost extra]# vim /etc/named.rfc1912.zones
zone "naccp.com" IN {
type master;
file "naccp.com.zone";
allow-update { none; };
};
[root@localhost extra]# cd /var/named
[root@localhost named]# cp -p accp.com.zone naccp.com.zone
[root@localhost named]# vim naccp.com.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.235.142
3.配置httpd扩展配置文件
[root@localhost conf]# cd /etc/httpd/conf/extra
[root@localhost extra]# vim vhost.conf
... //省略部分不做修改,追加以下内容
<VirtualHost 192.168.235.142:80>
Documentroot "/var/www/html/accp02/"
ServerName www.naccp.com
Errorlog "logs/www.accp02.com.error_log"
Customlog "logs/www.accp02.com.access_log" common
<Directory "/var/www/html/">
AuthName "DocumentRoot" //声明条目
AuthType Basic //基本验证类型
AuthUserFile /etc/httpd/conf/pwd //验证文件目录
Require valid-user //授权用户的验证
</Directory>
</VirtualHost>
[root@localhost extra]# systemctl restart httpd //重启服务
4使用客户机测试网页
标签:pre 域名 lan strong wal local root ESS 地址
原文地址:https://blog.51cto.com/14449521/2444924