实验目的:

一、创建两个基于域名的虚拟主机

1.www.baidu.com:只允许192.168.1.0/24网段访问,网页目录为/a

2.www.guge.com:增加用户验证,网页目录为/b

实验准备:

一台centos7服务器   192.168.1.60               安装Apache并发布

客户机                        192.168.1.49               测试Apache网站

实验步骤:

[[email protected] ~]# systemctl stop firewalld.service

[[email protected] ~]# systemctl disable firewalld.service

[[email protected] ~]# setenforce 0

 

安装httpd

https://blog.csdn.net/qq482929763/article/details/107806882

 

部署网页目录:

[[email protected] httpd]# mkdir   /a

[[email protected] httpd]# mkdir   /b

[[email protected] a]# echo  "baidu" >> /a/index.html

[[email protected] b]# echo  "guge" >> /b/index.html

 

创建用户认证文件

[[email protected] extra]# cd /usr/local/httpd/

[[email protected] httpd]# bin/htpasswd  -c /usr/local/httpd/conf/.awspwd   webadmin

New password:                                                                                 根据提示设置密码

Re-type new password:

Adding password for user webadmin

[[email protected] httpd]# cat /usr/local/httpd/conf/.awspwd                确认用户数据

webadmin:$apr1$swpb0jxU$iS/UEHGVIMF7KZECuhmwq0

 

修改httpd的虚拟主机配置文件:

[[email protected] httpd]# vim  /usr/local/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/a"

    ServerName www.baidu.com

    ServerAlias www.dummy-host.example.com

    ErrorLog "logs/dummy-host.example.com-error_log"

    CustomLog "logs/dummy-host.example.com-access_log" common

       <Directory "/a">

     Require all denied

     Require ip  192.168.1.0/24

     </Directory>

</VirtualHost>

 

<VirtualHost *:80>                                                                     //创建独立的配置文件

    ServerAdmin [email protected]      //设置虚拟站点区域(邮箱)

    DocumentRoot "/b"

    ServerName www.guge.com

    ErrorLog "logs/dummy-host2.example.com-error_log"

    CustomLog "logs/dummy-host2.example.com-access_log" common

     <Directory "/b">                                                                //设置目录访问权限

    <Directory "/b">

     AuthName "nihao"

     AuthType Basic

     AuthUserFile /usr/local/httpd//conf/.awspwd

     Require valid-user

     </Directory>

</VirtualHost>

 

Ps:<VirtualHost *:80>……</VirtualHost>称为虚拟主机区域

<Directory "目录位置">……</Directory>称为目录权限

认证分为摘要认证(不是所有浏览器都支持摘要认证)和基本认证(basic)

 

客户机限制:

Require all denied :拒绝所有主机访问

Require all granted:允许所有主机访问

Require local:仅允许本地主机访问

 

 

修改httpd的全局配置文件去掉注释

[[email protected] local]# vim /usr/local/httpd/conf/httpd.conf

482   Include conf/extra/httpd-vhosts.conf          //加载独立的配置文件

Systemctl   restart   httpd                                  //重启服务

 

在客户机添加hosts文件

[[email protected] ~]# vim /etc/hosts

192.168.1.61    www.baidu.com

192.168.1.61    www.guge.com

测试访问:

WEB网站服务(二)Apache 02WEB网站服务(二)Apache 02

 

 

相关文章: