Apache虚拟主机的访问方式(基于权限)

本章接上篇Apache虚拟主机的访问方式

———————————————————————————————————————————————html

Apache配置与应用

本章结构java

Apache配置剖析:

1.Apache链接保持
2.Apache访问控制数据库

Apache日志管理:

1.日志分割
2.AWStats日志分析vim

Apache链接保持

Apache链接保持相关参数

1.KeepAlive:
是否打开链接保持,OFF关闭,ON打开
2.KeepAlive' Timeout
一次链接屡次请求之间的最大间隔时间,两次请求超过该时间链接断开
3.MaxKeepAliveRequests:浏览器

一次链接可以传输的最大请求数量ide

Apache访问控制概述

Apache访问控制

1.做用:
控制对网站资源的访问
为特定的网站目录添加访问受权
2.经常使用访问控制方式
客户机地址限制:
用户受权限制测试

基于客户端地址的访问控制

1.使用Require配置项实现访问控制,按前后顺序限制
2.可用于< Location >、< Directory >、 < Files >、 < Limit >配置段中
3.Require配置项的常见语法

Require all granted
Require all denied
Require local
Require [not] host <主机名或域名列表>
Require [not] ip < IP地址或网段列表>网站

#使用not禁止访问时要将其置于<RequireAll> </RequireAll>容器中并在容器中指定相应的限制策略ui

Demo:用户受权限制访问

添加用户受权配置:

[root@localhost named]# cd /etc/httpd/conf/extra
[root@localhost extra]# ls
vhost.conf
[root@localhost extra]# vim vhost.conf
<VirtualHost 192.168.56.131:80>
  DocumentRoot "/var/www/html/accp/"
  ServerName www.accp.com
  ErrorLog "logs/www.accp.com.error_log"
  CustomLog "logs/www.accp.com.access_log" common
  <Directory "/var/www/html/">
    <RequireAll>
    Require not ip 192.168.56.130       //添加不容许的IP地址,为测试主机win7的IP地址
    Require all granted
    </RequireAll>
  </Directory>
</VirtualHost>
#此时能够访问accp02网段,不能够访问accp网段
修改完成后按Esc,输入:wq保存退出
[root@localhost extra]# systemctl restart httpd

验证黑白名单设置:

此时输入:www.naccp.com是正常能够访问咱们写的首页的内容的

在这里插入图片描述

可是咱们再输入:www.accp.com就会跳转到Apache的主页,而不是咱们写的主页内容了,说明黑白名单设置成功

在这里插入图片描述

建立用户认证数据库:

[root@localhost extra]# cd /etc/httpd/conf
[root@localhost conf]# ls
extra  httpd.conf  magic
[root@localhost conf]# htpasswd -c /etc/httpd/conf/pwd test01
New password:               //此处为:abc1234,可自行定义
Re-type new password:       //此处重复输入上面的密码
Adding password for user test01
[root@localhost conf]# ls       //此时能够看到pwd文件
extra  httpd.conf  magic  pwd
[root@localhost conf]# cat pwd
test01:$apr1$PsatL6Av$SVm5oEaVh6YbnRU4NOBH./        //这个就是test01的密码密文
[root@localhost conf]# htpasswd /etc/httpd/conf/pwd test02
New password: 
Re-type new password: 
Adding password for user test02
[root@localhost conf]# cat pwd
test01:$apr1$PsatL6Av$SVm5oEaVh6YbnRU4NOBH./
test02:$apr1$XzM8x3.v$Ozy.U6GXVzMaBKB4MKdMd/

[root@localhost conf]# cd extra/
[root@localhost extra]# ls
vhost.conf
[root@localhost extra]# vim vhost.conf
<VirtualHost 192.168.56.134: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     //重启服务

验证:

在win7的浏览器中输入:www.naccp.com,回车后提示咱们须要输入用户名和密码
此处咱们输入以前设置的用户名:test01,密码:abc1234,点击登录后就能够看到咱们以前写的网页主页内容了

在这里插入图片描述
在这里插入图片描述

相关文章
相关标签/搜索