linux 之web服务APACHE,建立httpd服务器,要求提供两个基于名称的虚拟主机:
实验目的
(1)www.X.com,页面文件目录为/web/vhosts/x;错误日志为
/var/log/httpd/x.err,访问日志为/var/log/httpd/x.access
(2)www.Y.com,页面文件目录为/web/vhosts/y;错误日志为 /var/log/httpd/www2.err,访问日志为/var/log/httpd/y.access
(3)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名
1、环境搭建
192.168.170.7 #Apache 服务器 192.168.170.6 #测试服务器
2、准备配置文件
vim /etc/httpd/conf.d/test.conf
<virtualhost *:80>
documentroot /web/vhosts/x
servername www.X.com
<Directory "/web/vhosts/x">
Require all granted
</Directory>
</virtualhost>
<virtualhost *:80>
documentroot /web/vhosts/y
servername www.Y.com
<Directory "/web/vhosts/y">
Require all granted
</Directory>
</virtualhost>
3.编辑默认配置文件修改访问日志,与错误日志路径
vim /etc/httpd/conf/httpd.conf ErrorLog "/var/log/httpd/www2.err" CustomLog "/var/log/httpd/y.access" combined
4.创建网点
mkdir /web/vhosts/x -pv echo '/web/vhosts/x/indexwebx.html' > /web/vhosts/x/index.html mkdir /web/vhosts/y -pv echo '/web/vhosts/y/indexweby.html' > /web/vhosts/y/index.html
5.启动服务
systemctl start httpd
ss -ntl
5.测试
在测试机子上 vim /etc/hosts 192.168.170.7 www.X.com www.Y.com
测试成功,到此实验结束
posted on 2020-12-19 15:35 jiapengchu 阅读(134) 评论(0) 编辑 收藏 举报