《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
相关推荐
能代全能带4 小时前
Centos挂载iso安装依赖包
linux·运维·centos
SeaTunnel5 小时前
Apache SeaTunnel 4 月有何新动作?连接器增强与 Zeta 稳定性提升等亮点速览
大数据·数据仓库·spark·apache·seatunnel
IT大白鼠6 小时前
CentOS 7操作系统安装、初始化配置与服务管理指南
centos
凡梦千华6 小时前
CentOS系统安装Elasticsearch,RPM包方式
linux·elasticsearch·centos
LoneEon1 天前
Kafka集群搭建指南:KRaft模式彻底摒弃Zookeeper
分布式·kafka·centos
坚持就完事了1 天前
Ubuntu和Centos中安装软件的命令
linux·ubuntu·centos
lifewange1 天前
VMware如何安装并配置CentOs镜像
linux·运维·centos
℡終嚸♂6802 天前
Apache Tomcat CVE-2025-55752 CTF Writeup
tomcat·apache·firefox
27669582922 天前
某白山小程序限制PC端调试
python·小程序·apache·小程序逆向·某白山·限制pc调试