一安装软件:yum,yum仓库
挂载本地光盘:
[root@localhost yum.repos.d]# cat base.repo
[base]
name=base
baseurl=file:///mnt/BaseOS
gpgcheck=0
[app]
name=appstream
baseurl=file:///mnt/AppStream
gpgcheck=0
[root@localhost yum.repos.d]# mount /dev/sr0 /mnt #挂载到本地光盘
二 、装包:
[root@localhost yum.repos.d]# yum install httpd -y
[root@localhost ~]# yum install mod_ssl httpd -y
三、更改配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
[root@localhost ~]# cat /etc/httpd/conf.d/vhosts.conf
<virtualhost 192.168.40.130:80>
servername www.openlab.com
documentroot /var/www/openlab
</virtualhost>
<directory /var/www/openlab>
allowoverride none
require all granted
</directory>
[root@localhost ~]# systemctl restart httpd #重启httpd协议
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld #关闭防火墙
[root@localhost ~]# mkdir /var/www/openlab #创建对应目录
[root@localhost ~]# echo welcome to openlab > /var/www/openlab/index.html #写入内容
四、第一题测试
[root@localhost conf.d]# vim /etc/hosts #在客户端修改hosts
[root@localhost conf.d]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.40.130 www.openlab.com
基于域名的网站,需要用到域名解析。 域名------->ip地址
windows下的hosts文件路径:C:\Windows\System32\drivers\etc\hosts
Linux下的hosts文件路径:/etc/hosts
[root@localhost conf.d]# curl www.openlab.com
welcome to openlab
五、第二题,创建目录,添加内容
[root@localhost ~]# mkdir /var/www/openlab/{student,data,money}
[root@localhost ~]# echo 这是学生信息网站 > /var/www/openlab/student/index.html
[root@localhost ~]# echo 这是教学资料网站 > /var/www/openlab/data/index.html
[root@localhost ~]# echo 这是缴费网站 > /var/www/openlab/money/index.html
六、第二题测试
[root@localhost conf.d]# curl www.openlab.com/data/
这是教学资料网站
七,创建用户
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
[root@localhost ~]# htpasswd -c /etc/httpd/mymima song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd -c /etc/httpd/mymima tian
New password:
Re-type new password:
Adding password for user tian
八、更改配置内容
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
[root@localhost ~]# cat /etc/httpd/conf.d/vhosts.conf
<directory /var/www/openlab/student>
allowoverride none
authtype basic
authname "please login"
authuserfile /etc/httpd/mymima
require user song tian
</directory>
九、第三题、一小问测试
[root@localhost conf.d]# curl www.openlab.com/student/ -u song
Enter host password for user 'song':
这是学生信息网站
[root@localhost conf.d]# curl www.openlab.com/student/ -u tian
Enter host password for user 'tian':
这是学生信息网站
十、更改配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
[root@localhost ~]# cat /etc/httpd/conf.d/vhosts.conf
<virtualhost 192.168.40.130:443>
servername www.openlab.com
documentroot /var/www/openlab/money
sslengine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
</virtualhost>
<directory /var/www/openlab/money>
allowoverride none
require all granted