1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
一 .
#创建文件夹
[root@localhost conf.d]# mkdir -pv /www/ip/{100,200}
#将要显示的html页面内容写入该文件夹中,文件名为index.html
[root@localhost conf.d]# echo "Welcome to openlab !!" > /www/ip/100/index.html
#编写配置文件
[root@localhost conf.d]# cat /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost 192.168.181.100:80>
DocumentRoot "/www/ip/100"
ServerName www.openlab.com
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/httpd/100-error_log"
</VritualHost>
<Directory "/www/ip">
AllowOverride None
Require all granted
</Directory>
#检查防火墙状态和selinux
[root@localhost 100]# getenforce
Permissive
[root@localhost 100]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
在windows中找到hosts,并在文件中编写ip和域名
最后浏览器访问www.openlab.com
二.
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网站访问缴费网站)。
#切换到存放html的文件夹
[root@localhost conf.d]# cd /www/ip/100
#创建学生目录
[root@localhost 100]# mkdir student
[root@localhost 100]# echo "this is student" > student/index.html
访问学生信息
#创建教学资料
[root@localhost 100]# mkdir jiaoxueziliao
[root@localhost 100]# echo "this is book" > jiaoxueziliao/index.html
访问教学资料
#创建缴费
[root@localhost 100]# mkdir money
[root@localhost 100]# echo "this is money" > money/index.html
访问缴费
三.
3.要求
(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。
第一小题:
#修改student控制文件
[root@localhost 100]# cat /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost 192.168.181.100:80>
DocumentRoot "/www/ip/100"
ServerName www.openlab.com
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/httpd/100-error_log"
</VirtualHost>
<Directory "/www/ip">
AllowOverride None
Require all granted
</Directory>
<directory /www/ip/100/student>
authtype basic
authname "please login:"
authuserfile /etc/httpd/mymima
require user song tian #test
</directory>
#增添指定登录用户
[root@localhost conf.d]# htpasswd -c /etc/httpd/mymima song
New password:
Re-type new password:
Adding password for user song
[root@localhost conf.d]# htpasswd /etc/httpd/mymima tian
New password:
Re-type new password:
Adding password for user tian
访问结果:
第二小题:
#创建CA证书和秘钥
[root@localhost certs]# openssl genrsa -aes128 2048 > jiami.key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
[root@localhost certs]# openssl req -utf8 -new -key jiami.key -x509 -days 100 -out jiami.crt
Enter pass phrase for jiami.key:
#https的配置文件
<virtualhost 192.168.181.100:443>
servername www.openlab.com
documentroot /www/ip/100
sslengine on
SSLCertificateFile /etc/pki/tls/certs/jiami.crt
SSLCertificateKeyFile /etc/pki/tls/certs/jiami.key
</virtualhost>
<directory /www/ip/100>
allowoverride none
require all granted
</directory>
访问结果