网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab.
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
要求:(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。
[root@localhost ~]# yum install httpd -y #下载http软件包
[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf #修改配置文件
[root@localhost ~]# vim /etc/hosts #手动修改文件,添加域名关联信息
客户端测试手动添加域名关联信息 window C:\Windows\System32\drivers\etc\hosts
[root@localhost ~]# mkdir /openlab #创建目录
[root@localhost ~]# echo welcome to openlab > /openlab/index.html
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# cat /openlab/index.html
welcome to openlab
[root@localhost ~]# curl http://www.openlab.com
welcome to openlab
[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf #修改配置文件
[root@localhost ~]# mkdir /openlab/{student,data,money} -pv
[root@localhost ~]# echo I am a student > /openlab/student/index.html
[root@localhost ~]# echo You are a data > /openlab/data/index.html
[root@localhost ~]# echo It is a money > /openlab/money/index.html
[root@localhost ~]# htpasswd -c /etc/httpd/user song
[root@localhost ~]# htpasswd /etc/httpd/user tian
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# cat /openlab/student/index.html
I am a student
[root@localhost ~]# cat /openlab/data/index.html
You are a data
[root@localhost ~]# curl http://www.openlab.com/student/ -u song
[root@localhost ~]# curl http://www.openlab.com/student/ -u tian
在Linux主机上访问http://www.openlab.com 输入用户名和密码进去访问(song和tianjunke)
[root@localhost ~]# yum install mod_ssl.x86_64 -y
[root@localhost certs]# vim /etc/httpd/conf.d/vhost.conf
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# cat /openlab/money/index.html
It is a money
[root@localhost ~]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code.
See "systemctl status httpd.service" and "journalctl -xe" for details.
因为我没有openlab加密证书,所以我重启服务失败,接下来搭建openlab加密证书文件
[root@localhost private]# cd /etc/pki/tls/certs/
[root@localhost certs]# cd ../private/
[root@localhost private]# openssl genrsa -aes128 2048 > openlab.key
[root@localhost private]# cd ../certs/
[root@localhost certs]# openssl req -utf8 -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out openlab.crt
详细步骤在我<https(web)搭建加密文件>这篇博客里
[root@localhost certs]# systemctl restart httpd
Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ******
[root@localhost certs]# curl http://www.openlab.com/money/
It is a money
[root@localhost certs]# curl http://www.openlab.com/data/
You are a data
在Linux主机上访问http://www.openlab.com/data/
在Linux主机上访问http://www.openlab.com/money/
再把学生信息写入www.openlab.com/student 网站,把教学资料写入www.openlab.com/data网站,把缴费写入www.openlab.com/money网站。
这样就成功啦!