Apache的2.4Require限制以及2.2版本的Order限制(四)

一、Apache访问权限介绍

1. 概念:

在linux中目录有目录权限,ftp也有相应的访问权限,那Apache如此强大,作为老古董延续至今当然也不会缺席,来一起看一下

2. 访问权限设置的方式:

1)通过IP进行限制
2)通过主机名进行限制

二、实验部分

1. Centos6中的httpd的2.2版本

实验环境,一台服务器IP为10.0.0.3,两台客户端IP分别为10.0.0.1与10.0.0.2
实验要求,使10.0.0.1可以访问而限制10.0.0.2或其他人不可访问
1)安装httpd 2.2版本
#Centos 6默认yum中安装的就是httpd的2.2版本
[root@localhost ~] yum install httpd -y
[root@localhost ~]# httpd -v
	Server version: Apache/2.2.15 (Unix)
	Server built:   Aug 13 2013 17:29:28

2)创建目录发布站点的目录以及主页文件
[root@localhost ~] mkdir -p /web/html
[root@localhost ~] echo "<h1>Welcome to my website</h1>" > /web/html/index.html
[root@localhost ~] cat /web/html/index.html 
	<h1>Welcome to my website</h1>

3)发布站点并设置访问权限并重启服务
[root@localhost ~] vim /etc/httpd/conf/httpd.conf
添加:
	DocumentRoot "/web"
	#发布该目录
	<Directory "/web/html">
	        Options None
	        AllowOverride None
	        Order allow,deny
	        Allow from 10.0.0.1
	        Deny from 10.0.0.2
	</Directory>
[root@localhost ~] service httpd restart

4)测试10.0.0.1是否可以访问
[root@localhost ~] wget http://10.0.0.3/html/index.html
	--2020-04-26 10:54:37--  http://10.0.0.3/html/index.html
	正在连接 10.0.0.3:80... 已连接。
	已发出 HTTP 请求,正在等待回应... 200 OK
	长度:31 [text/html]
	正在保存至: “index.html”
	
	100%[=====================================>] 31          --.-K/s 用时 0s      
	
	2020-04-26 10:54:37 (6.48 MB/s) - 已保存 “index.html” [31/31])
	
5)测试10.0.0.2是否可以访问
[root@localhost ~] wget http://10.0.0.3/html/index.html
	--2020-04-26 10:55:16--  http://10.0.0.3/html/index.html
	正在连接 10.0.0.3:80... 已连接。
	已发出 HTTP 请求,正在等待回应... 403 Forbidden
	2020-04-26 10:55:16 错误 403:Forbidden。
#测试成功,出现Forbidden字样,禁止该10.0.0.2登录成功

2.httpd 2.2版本的Order字段介绍

字段格式:Order [allow | deny]  [allow | deny] 
#前一字段规定了手动设置的权限
#后一字段代表的是默认规则

3.Centos7中的httpd 2.4版本

实验环境,一台服务器IP为10.0.0.2,两台客户端IP分别为10.0.0.1与10.0.0.3
实验要求,使10.0.0.1可以访问而限制10.0.0.3不可访问
1)安装httpd 2.4版本
[root@localhost ~] yum install httpd -y
[root@localhost ~] httpd -v
	Server version: Apache/2.4.6 (CentOS)
	Server built:   Apr 20 2018 18:10:38

2)创建目录发布站点的目录以及主页文件
[root@localhost ~] mkdir -p /web/html
[root@localhost ~] echo "<h1>Welcome to my website</h1>" > /web/html/index.html
[root@localhost ~] cat /web/html/index.html 
	<h1>Welcome to my website</h1>

3)发布站点目录,并制定权限
[root@localhost ~] vim /etc/httpd/conf/httpd.conf
DocumentRoot "/web"
<Directory "/web/html">
        Options None
        AllowOverride None
        <RequireAll>
                Require ip 10.0.0.1
                Require not ip 10.0.0.3
        </RequireAll>
</Directory>
[root@localhost ~] systemctl restart httpd

4)测试10.0.0.1是否可以访问?
[root@localhost ~] wget http://10.0.0.2/html/index.html
	--2020-04-26 11:07:40--  http://10.0.0.2/html/index.html
	正在连接 10.0.0.2:80... 已连接。
	已发出 HTTP 请求,正在等待回应... 200 OK
	长度:31 [text/html]
	正在保存至: “index.html.1”
	
	100%[============================================================================================>] 31          --.-K/s 用时 0s      
	
	2020-04-26 11:07:40 (6.93 MB/s) - 已保存 “index.html.1” [31/31])

5)测试10.0.0.2是否可以访问?
[root@localhost ~] wget http://10.0.0.2/html/index.html
	--2020-04-26 11:07:56--  http://10.0.0.2/html/index.html
	正在连接 10.0.0.2:80... 已连接。
	已发出 HTTP 请求,正在等待回应... 403 Forbidden
	2020-04-26 11:07:56 错误 403:Forbidden。
#成功!显示Forbidden没有权限访问

4.httpd 2.4版本的Require字段介绍

字段格式:
IP地址限制:
<RequireAll>
	Require ip ip_address
	Require not ip ip_address
</RequireAll>

主机名限制:
<RequireAll>
	Require host host_name
	Require not host host_name
</RequireAll>

全部允许或全部禁止:
Require all granted		//全部允许
Require all denied		//全部禁止
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值