Liunx服务器中基于https搭建Web网站

综合练习:请给openlab搭建web网站
网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个虚拟网站目录分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
3.要求(1)学生信息网站只有song和tian两人可以访问,其他网站所有用户用能访问。 student
(2)访问缴费网站实现数据加密基于https访问。

实验如下所示
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
首先安装http软件包,关闭Firewalld和setlinux

[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# getenforce 0 --临时关闭setLinux
[root@localhost ~]# mount /dev/sr0 /mnt  --挂载光盘

进入配置文件中配置网页信息

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<Virtualhost 192.168.207.128:80>
        Documentroot  /openlab/128
        ServerName      www.openlab.com
</Virtualhost>
<Directory /openlab>
        AllowOverride none
        Require all granted
</Directory>
[root@localhost ~]# mkdir /openlab/128 -pv
mkdir: created directory '/openlab'
mkdir: created directory '/openlab/128'
[root@localhost ~]# echo welcome to openlab!!! > /openlab/128/index.html

然后进入本地编写hosts文件和windows主机填写hosts文件(主机位置于C:\Windows\System32\drivers\etc\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.207.128 www.openlab.com

在Linux主机上浏览
在这里插入图片描述
在网页中浏览网址
在这里插入图片描述
2.给该公司创建三个虚拟网站目录分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。

进入网页编辑里面创建虚拟目录

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<Virtualhost 192.168.207.128:80>
        Documentroot  /openlab/128
        ServerName      www.openlab.com
        alias /student  /students
        alias /data     /datas
        alias /money    /moneys
</Virtualhost>
<Directory /openlab>
        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>

创建相应的目录和填写内容

[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   --完成相应配置后重启服务

在Linux内测试
在这里插入图片描述
3.要求(1)学生信息网站只有song和tian两人可以访问,其他网站所有用户用能访问。 student
(2)访问缴费网站实现数据加密基于https访问。

在student的虚拟目录里设置访问控制,然后创建相应的用户

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<Directory /students>
        AuthType Basic
        AuthName "Please login:"
        AuthUserFile /etc/httpd/users
        Require user song,tian
[root@localhost ~]# htpasswd -c /etc/httpd/users song --指定创建用户时并创建目录
New password: 
Re-type new password: 
Adding password for user song
[root@localhost ~]# htpasswd /etc/httpd/users tian
New password: 
Re-type new password: 
Adding password for user tian

(2)访问缴费网站实现数据加密基于https访问。

创建证书密匙和证书文件

[root@localhost /]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl genrsa -aes128 2048 > openlab.key
Generating RSA private key, 2048 bit long modulus (2 primes)
.................................+++++
.......................................................+++++
e is 65537 (0x010001)
Enter pass phrase:
Verifying - Enter pass phrase:
[root@localhost certs]# openssl req -utf8 -new -key openlab.key -x509 -days 365 -out openlab.crt
Enter pass phrase for 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) []:GD
Locality Name (eg, city) [Default City]:guangzhou
Organization Name (eg, company) [Default Company Ltd]:openlab    
Organizational Unit Name (eg, section) []:openlab 
Common Name (eg, your name or your server's hostname) []:
Email Address []:admin@admin

在虚拟主机目录里配置网页证书和证书密匙

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<Virtualhost 192.168.207.128:443>   --监听端口改为443
        Documentroot  /openlab/128
        ServerName      www.openlab.com
        alias /student  /students
        SSLEngine on
        SSLCertificateFile /etc/pki/tls/certs/openlab.crt
        SSLCertificateKeyFile /etc/pki/tls/certs/openlab.key
</Virtualhost>
[root@localhost ~]# systemctl restart httpd    --重启服务

网页测试结果如下
在这里插入图片描述
至此实验完成!
希望本实验也对你有帮助谢谢。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值