网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
[root@server conf.d]# mkdir /www/openlab
[root@server conf.d]# echo welcome to openlab!!! > /www/openlab/index.html
[root@server openlab]# cat /etc/httpd/conf.d/myhosts.conf.bak
<Directory /www>AllowOverride noneRequire all granted
</Directory>
<VirtualHost 192.168.180.136:80>DocumentRoot /www/openlabServerName www.openlab.com
</VirtualHost>
[root@server openlab]# curl http://www.openlab.com
welcome to openlab
[root@server conf.d]# mkdir /www/openlab
[root@server conf.d]# echo welcome to openlab!!! > /www/openlab/index.html
[root@server openlab]# cat /etc/httpd/conf.d/myhosts.conf.bak
配置文件
<Directory /www>AllowOverride noneRequire all granted
</Directory>
<VirtualHost 192.168.180.136:80>DocumentRoot /www/openlabServerName www.openlab.com
</VirtualHost>
[root@server openlab]# vim /etc/hosts
192.168.180.136 www.openlab.com[root@server openlab]# systemctl restart httpd[root@server openlab]# curl http://www.openlab.com
welcome to openlab!!!
2.给该公司创建三个网站目录分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
<Directory /www/openlab>AllowOverride noneRequire all granted
</Directory><VirtualHost 192.168.180.150:80>DocumentRoot /www/openlabServerName www.openlab.comalias /student /www/openlab/studentalias /data /www/openlab/dataalias /money /www/openlab/money
</VirtualHost>mkdir -pv /www/openlab/student
mkdir -pv /www/openlab/data
mkdir -pv /www/openlab/money
echo "学生信息" > /www/openlab/student/index.html
echo "教学资料" > /www/openlab/data/index.html
echo "缴费" > /www/openlab/money/index.htmlsystemctl restart httpd
[root@server ~]# curl www.openlab.com/student/
学生信息
[root@server ~]# curl www.openlab.com/data/
教学资料
[root@server ~]# curl www.openlab.com/money/
<Directory /www/openlab>AllowOverride noneRequire all granted
</Directory><VirtualHost 192.168.180.150:80>DocumentRoot /www/openlabServerName www.openlab.comalias /student /www/openlab/studentalias /data /www/openlab/dataalias /money /www/openlab/money
</VirtualHost>mkdir -pv /www/openlab/student
mkdir -pv /www/openlab/data
mkdir -pv /www/openlab/money
echo "学生信息" > /www/openlab/student/index.html
echo "教学资料" > /www/openlab/data/index.html
echo "缴费" > /www/openlab/money/index.htmlsystemctl restart httpd
3.要求
(1)学生信息网站只有song和tian两人可以访问,其他网站所有用户用能访问。
[root@server ~]# vim /etc/httpd/conf.d/myhosts.conf <Directory /www/openlab>AllowOverride noneRequire all granted
</Directory><Directory /www/openlab>AuthType basicAuthName "Please Login"AuthUserFile /usr/local/http_user/passwdRequire user song tian</Directory><VirtualHost 192.168.180.150:80>DocumentRoot /www/openlabServerName www.openlab.comalias /student /www/openlab/studentalias /data /www/openlab/dataalias /money /www/openlab/money
</VirtualHost>[root@server ~]# curl www.openlab.com/student/ -u song
Enter host password for user 'song':
学生信息
(2)访问缴费网站实现数据加密基于https访问
[root@www conf.d]# yum install mod_ssl httpd -y
[root@www conf.d]# cd /etc/pki/tls/certs/
#制作密钥及证书[root@server certs]# openssl genrsa 2048 > openlab1.key
[root@server certs]# openssl req -utf8 -new -key /etc/pki/tls/certs/openlab1.key -x509 -days 365 -out openlab1.crt
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) []:shannxi
Locality Name (eg, city) [Default City]:xian
Organization Name (eg, company) [Default Company Ltd]:www.openlab1.com
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:admin@admin.com
[root@server certs]# vim /etc/httpd/conf.d/myhosts.conf<VirtualHost 192.168.180.150:443>DocumentRoot /www/openlabServerName www.openlab.comSSLEngine onSSLCertificateFile /etc/pki/tls/certs/openlab1.crtSSLCertificateKeyFile /etc/pki/tls/certs/openlab1.keyalias /student /www/openlab/studentalias /data /www/openlab/dataalias /money /www/openlab/money
</VirtualHost>systemctl restart httpd
显示界面,将继续访问
缴费
[root@server private]# curl https://www.openlab.com/money/ -k