搭建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两人可以访问,其他用户不能访问

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

实验过程

第一步:准备工作

# 恢复快照,关闭安全软件

[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld       

#安装httpd服务和mod_ssl包

[root@server ~]# yum  install httpd  mod_ssl -y

#添加 hosts映射
[root@server ~]# vim  /etc/hosts
192.168.100.133  www.openlab.com

第二步:创建www.openlab.com网站

# 创建网页目录及网页
[root@server ~]# mkdir -p /www/openlab
[root@server ~]# echo "welcome to openlab vim /etc/hosts!" > /www/openlab/index.html

#编辑主配置文件

[root@server ~]# vim /etc/httpd/conf/httpd.conf 
<VirtualHost 192.168.100.133>
        DocumentRoot /www/openlab
        ServerName "www.openlab.com"
        <Directory /www/openlab>
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>
#在主配置文件中添加以上信息

#重启服务,并测试

[root@server ~]# systemctl restart httpd

# linux端打开浏览器输入www.openlab.com测试

第三步:创建教学资料子网站www.openlab.com/data

[root@server ~]# mkdir /www/openlab/data
[root@server ~]# echo 'data' > /www/openlab/data/index.html
[root@server ~]# vim /etc/httpd/conf/httpd.conf   # 接着之前的继续向下编写
<VirtualHost  192.168.100.133>           
        DocumentRoot /www/openlab/data
        alias /data /www/openlab/data
        ServerName "www.openlab.com"
        <Directory /www/openlab/data>
                AllowOverride none
                Require all granted
        </Directory>
</VirtualHost>

[root@server ~]# systemctl restart  httpd
# linux端打开浏览器输入www.openlab.com/data测试

第四步:创建学生信息子网站www.openlab.com/student

[root@server ~]# mkdir /www/openlab/student
[root@server ~]# echo 'student' > /www/openlab/student/index.html
[root@server ~]# useradd song
[root@server ~]# passwa song    # 密码123456
[root@server ~]# useradd tian
[root@server ~]# passwd tian    # 密码654321
[root@server ~]# htpasswd -c /etc/httpd/passwd song  # 密码123456
[root@server ~]# htpasswd  /etc/httpd/passwd tian    # 密码654321
[root@server ~]# vim /etc/httpd/conf/httpd.conf   # 接着之前的继续向下编写
<Directory /www/openlab/student>
        authuserfile  /etc/httpd/passwd
        authname  "student"
        authtype  basic
        require   user  song  tian
</Directory>
[root@server ~]# systemctl restart  httpd
# linux端打开浏览器输入www.openlab.com/student测试,多次测试需要清除浏览器缓存

 

 

第五步:创建缴费子网站www.openlab.com/money.

[root@server ~]# mkdir /www/openlab/money

[root@server ~]# echo 'money' > /www/openlab/money/index.html

[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/money.key
Enter PEM pass phrase:         # 私钥加密密码123456
Verifying - Enter PEM pass phrase:  # 在输入一遍123456

[root@server ~]# openssl req -utf8 -new -key /etc/pki/tls/private/money.key -x509 -days 365 -out /etc/pki/tls/certs/money.crt
Enter pass phrase for /etc/pki/tls/private/money.key: # 输入私钥加密密码123456
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) []:shanxi
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:openlab
Organizational Unit Name (eg, section) []:RHCE    
Common Name (eg, your name or your server's hostname) []:www.openlab.com
Email Address []:lisa@qq.com

[root@server ~]# vim /etc/httpd/conf/httpd.conf 
<VirtualHost 192.168.100.133:443>
        SSLEngine on
        SSLCertificateFile /etc/pki/tls/certs/money.crt
        SSLCertificatekeyFile /etc/pki/tls/private/money.key
        ServerName  www.openlab.com
        DocumentRoot /www/openlab
        alias /money /www/openlab/money
        <Directory /www/openlab/money>
                AllowOverride none
                require all granted
        </Directory>
</VirtualHost>
[root@server ~]# systemctl restart  httpd   # 需要输入私钥加密密码123456
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ******                  
# linux端打开浏览器输入https://www.openlab.com/money测试

 

以上内容仅供参考