https、虚拟目录、用户控制搭建web实验

https、虚拟目录、用户控制搭建web实验

实验要求

  1. 基于域名www.openlab.com可以访问网站内容为“welcom to openlab!!!”

  2. 给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student网站访问学生信息,www.openlab.com/data网站访问教学资料www.openlab.com/money网站访问缴费网站。

  3. 要求

    学生信息网站只有zhangsan和lisi两个人可以访问,其他用户不能访问

    访问缴费网站实现数据加密基于https访问

搭建虚拟目录和用户控制的web

🚀在开始实验之前,要配置好本地yum源、安装http包,关闭firewalld和selinuxsetenforce 0

[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0 

🚀在/etc/httpd/conf.d/vhosts.conf创建虚拟主机配置文件,并且配置域名为www.openlab.com的web网站

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<Virtualhost 192.168.133.150:80>
        Documentroot /www/openlab
        ServerName www.openlab.com
</Virtualhost>

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
[root@localhost ~]# mkdir -pv /www/openlab
mkdir: created directory '/www'
mkdir: created directory '/www/openlab'
[root@localhost ~]# echo "welcome to openlab!!!" > /www/openlab/index.html
echo "welcome to openlabmkdir -pv /www/openlab!" > /www/openlab/index.html

🚀配置本地和windows的hosts文件

[root@localhost ~]# vim /etc/hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.133.150 www.openlab.com
[root@localhost ~]# curl www.openlab.com
welcome to openlab!!!

创建虚拟目录

🚀通过别名创建虚拟目录并且目录标签定义

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<Virtualhost 192.168.133.150:80>
        Documentroot /www/openlab
        ServerName www.openlab.com
        alias /student /students
        alias /data /datas
        alias /money /moneys
</Virtualhost>
<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
<Directory /students>
        AllowOverride none
        Require all granted
</Directory>
<Directory /datas>
        AllowOverride none
        Require all granted
</Directory>
<Directory /moneys>
        AllowOverride none
        Require all granted
</Directory>

🚀创建相应的目录和内容,并且在linux中测试

[root@localhost ~]# mkdir /{students,datas,moneys}
[root@localhost ~]# echo "学生信息" > /students/index.html
[root@localhost ~]# echo "教学资料" > /datas/index.html
[root@localhost ~]# echo "缴费网站" > /moneys/index.html
[root@localhost ~]# systemctl restart httpd.service 
[root@localhost ~]# curl www.openlab.com/student/
学生信息
[root@localhost ~]# curl www.openlab.com/data/
教学资料
[root@localhost ~]# curl www.openlab.com/money/
缴费网站

用户控制

🚀在配置文件student的目录标签里设置访问控制,然后创建相应的用户

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<Virtualhost 192.168.133.150:80>
        Documentroot /www/openlab
        ServerName www.openlab.com
        alias /student /www/students
        alias /data /www/datas
        alias /money /www/moneys
</Virtualhost>

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
<Directory /students>
		AllowOverride none
        AuthType Basic
        AuthName "Please login:"
        AuthUserFile /etc/httpd/users
        Require user zhangsan lisi
</Directory>
<Directory /datas>
        AllowOverride none
        Require all granted
</Directory>
<Directory /moneys>
        AllowOverride none
        Require all granted
</Directory>
[root@localhost ~]# htpasswd -c /etc/httpd/user zhangsan
New password: 
Re-type new password: 
Adding password for user zhangsan
[root@localhost ~]# htpasswd /etc/httpd/user lisi
New password: 
Re-type new password: 
Adding password for user lisi

访问缴费网站基于https

😊创建证书密钥和证书文件

[root@localhost ~]# openssl req -newkey rsa -nodes -keyout openlab.key -x509 -days 365 -out openlab.crtt
Generating a RSA private key
.................................................+++++
...........................................................................+++++
writing new private key to 'openlab.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:86
State or Province Name (full name) []:jiangsu
Locality Name (eg, city) [Default City]:nanjing
Organization Name (eg, company) [Default Company Ltd]:nanhang
Organizational Unit Name (eg, section) []:zj    
Common Name (eg, your name or your server's hostname) []:zj
Email Address []:root@localhost

😊在vhost配置文件中配置

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
<Virtualhost 192.168.133.150:80>
        Documentroot /www/openlab
        ServerName www.openlab.com
        alias /student /www/students
        alias /data /www/datas
</Virtualhost>
<Virtualhost 192.168.133.150:443>
        Documentroot /www/moneys
        ServerName www.openlab.com
        alias /money /www/moneys
        SSLEngine on
        SSLCertificateFile /root/openlab.crtt
        SSLCertificatekeyFile /root/openlab.key
</Virtualhost>

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
<Directory /students>
        AllowOverride none
        AuthType Basic
        AuthName "Please login:"
        AuthUserFile /etc/httpd/users
        Require user zhangsan lisi
</Directory>
<Directory /datas>
        AllowOverride none
        Require all granted
</Directory>
<Directory /moneys>
        AllowOverride none
        Require all granted
</Directory>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿瑾~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值