HTTP综合练习题web网站

综合练习:请给openlab搭建web网站

​网站需求:

​1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!

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

​[www.openlab.com/money网站访问缴费网站](http://www.openlab.com/money网站访问缴费网站)。

​3.要求

​ (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。

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

题目解析步骤:

准备工作

[root@server ~]# systemctl stop firewalld

[root@server ~]# setenforce 0

[root@server ~]# yum install httpd -y (如果之前没有永久挂载需要挂载后安装软件包)

编辑访问文件(域名解析,客户端在那个上验证,就写在那个主机上)

[root@server ~]# vim /etc/hosts

192.168.145.128 www.openlab.com

[root@server ~]# ping www.openlab.com

编辑配置文件

[root@server ~]# vim /etc/httpd/conf.d/li.conf

<VirtualHost 192.168.145.128:80>

DocumentRoot /www/openlab

ServerName www.openlab.com

</VirtualHost>

<Directory /www>

AllowOverride none

Require all granted

</Directory>

创建网站存储文件

[root@server ~]# mkdir /www/openlab -pv

文件中写上需要内容

[root@server ~]# echo 'welcome to openlab!!!' > /www/openlab/index.html(如果单引号和双引号都有问题,用vim进行编辑)

重启服务

[root@server ~]# systemctl restart httpd

测试

[root@server ~]# curl http://www.openlab.com

welcome to openlab !!!

创建子文件(通过真实路径)

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

[root@server ~]# echo this is data > /www/openlab/data/index.html[root@server ~]# curl http://www.openlab.com/data/

this is data

创建students真实路径,及书写内容

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

[root@server ~]# echo this is student > /www/openlab/student/index.html

编辑配置文件完成student的要求认证

[root@server ~]# vim /etc/httpd/conf.d/li.conf

<VirtualHost 192.168.145.128:80>

DocumentRoot /www/openlab

ServerName www.openlab.com

</VirtualHost>

<Directory /www>

AllowOverride none

Require all granted

</Directory>

<Directory /www/openlab/student>

AuthType Basic

AuthName "login......"

AuthUserFile /etc/httpd/users

Require user song tian

</Directory>

创建用户

[root@server openlab]# htpasswd -c /etc/httpd/users song

New password: 1205

Re-type new password: 1205

Adding password for user song

[root@server openlab]# htpasswd /etc/httpd/users tian

New password: 1234

Re-type new password: 1234

Adding password for user tian

重启服务

[root@server openlab]# systemctl restart httpd

测试

[root@server ~]# curl http://www.openlab.com/student/

[root@server ~]# curl http://www.openlab.com/student/ -u song:1205this is student

安装

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

找到密钥配置文件

[root@server ~]# cd /etc/httpd/conf.d/

[root@server conf.d]# ll

total 32

-rw-r--r-- 1 root root 2916 Apr 14 17:23 autoindex.conf

-rw-r--r-- 1 root root 490 Jul 10 21:15 li.conf

-rw-r--r-- 1 root root 400 Apr 14 17:24 README

-rw-r--r-- 1 root root 8720 Apr 14 17:22 ssl.conf

-rw-r--r-- 1 root root 1252 Apr 14 17:22 userdir.conf

-rw-r--r-- 1 root root 653 Apr 14 17:22 welcome.conf

[root@server conf.d]# vim ssl.conf

编辑配置文件

[root@server conf.d]# vim /etc/httpd/conf.d/li.conf

<VirtualHost 192.168.145.128:80>

DocumentRoot /www/openlab

ServerName www.openlab.com

</VirtualHost>

<Directory /www>

AllowOverride none

Require all granted

</Directory>

<Directory /www/openlab/student>

AuthType Basic

AuthName "login......"

AuthUserFile /etc/httpd/users

Require user song tian

</Directory>

<VirtualHost 192.168.145.128:443>

DocumentRoot /www/li

ServerName www.openlab.com

SSLEngine on

SSLCertificateFile /certs/lili.crt

SSLCertificateKeyFile /private/lili.key

</VirtualHost>

[root@server ~]# mkdir /www/li

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

[root@server ~]# echo this is money > /www/li/money/index.html

[root@server ~]# mkdir /certs

[root@server ~]# mkdir /private

配置密钥

第一种方法

[root@server conf.d]# openssl req -newkey rsa:4096 -keyout /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt

[root@server ~]# openssl genrsa 2048 > /private/lili.key

[root@server ~]# openssl req -new -key /private/lili.key -x509 -days 365 -out /certs/lili.crt

重启服务

[root@server ~]# vim /etc/httpd/conf.d/li.conf

测试

root@server ~]# curl -k https://www.openlab.com/ --趋于该主机访问没有界面

[root@server ~]# curl -k https://www.openlab.com/money/

this is money