《HCIP-openEuler实验指导手册》1.7 Apache虚拟主机配置

知识点

配置步骤

  1. 需求
域名 访问目录
test1.com /home/source/test1
test2.com /home/source/test2
test3.com /home/source/test3
  1. 创建配置文件
bash 复制代码
touch /etc/httpd/conf.d/vhost.conf
vim /etc/httpd/conf.d/vhost.conf

文件内容如下

bash 复制代码
<VirtualHost *.81>
ServerName test1.com
DocumentRoot "/home/source/test1"
<Directory "/home/source/test1">
AllowOverride None
#Allow open access:
Require all granted
</Directory>
DirectoryIndex test1.html
</VirtualHost>

<VirtualHost *.81>
ServerName test2.com
DocumentRoot "/home/source/test2"
<Directory "/home/source/test2">
AllowOverride None
#Allow open access:
Require all granted
</Directory>
DirectoryIndex test2.html
</VirtualHost>

<VirtualHost *.81>
ServerName test3.com
DocumentRoot "/home/source/test3"
<Directory "/home/source/test1">
AllowOverride None
#Allow open access:
Require all granted
</Directory>
DirectoryIndex test3.html
</VirtualHost>

将上次实验/etc/httpd/conf.d/source.conf去除

bash 复制代码
cd /etc/httpd/conf.d
mv source.conf source.conf.bak
  1. 准备访问文件
bash 复制代码
echo "this is /test1/test1" > /home/source/test1/test1.html
echo "this is /test2/test2" > /home/source/test2/test2.html
echo "this is /test3/test3" > /home/source/test3/test3.html
systemctl restart httpd
  1. 修改host文件
bash 复制代码
vim /etc/hosts

加入如下内容

127.0.0.1 test1.com

127.0.0.1 test2.com

127.0.0.1 test3.com

  1. 重启服务器测试
bash 复制代码
curl test1.com:81
curl test2.com:81
curl test3.com:81
相关推荐
Apache Flink5 小时前
Apache Flink 流批融合技术介绍
人工智能·flink·apache
程序员皮皮林1 天前
开源PDF工具 Apache PDFBox 认识及使用(知识点+案例)
java·pdf·开源·apache
前端-文龙刚1 天前
小程序给对象赋值(双向绑定)方法之一
服务器·小程序·apache
大广-全栈开发1 天前
centos 7 安装gitlab
linux·git·centos
悲伤的创可贴1 天前
Docker安装以及简单使用
linux·docker·centos
小安运维日记1 天前
Linux云计算 |【第三阶段】PROJECT1-DAY1
linux·运维·云计算·apache
nfgo1 天前
快速体验Linux发行版:DistroSea详解与操作指南
linux·ubuntu·centos
weixin_424215841 天前
shell运算实战案例-KFC点餐系统
linux·centos
鱼饼6号1 天前
Prometheus 上手指南
linux·运维·centos·prometheus
学习3人组2 天前
CentOS 中配置 OpenJDK以及多版本管理
linux·运维·centos