《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
相关推荐
chairon6 小时前
Ansible:playbook的高级用法
linux·运维·服务器·ansible·apache
曼岛_11 小时前
CentOS 7 强制升级Docker 24.x终极指南(解决MySQL8镜像兼容性问题)
linux·docker·centos
Fanche40412 小时前
Linux-CentOS-7—— 安装MySQL 8
linux·运维·数据库·mysql·centos
三次握手四次挥手15 小时前
Apache Kafka全栈技术解析
分布式·kafka·apache
晴空๓17 小时前
在CentOS上安装Docker需要注意的事项
linux·docker·centos
搜搜秀17 小时前
linux (CentOS 10)使用传统程序语言(C)进行编译---主,子程序连接:子程序的编译
linux·c语言·centos
檬柠wan17 小时前
CentOS 7 yum 无法安装软件的解决方法
linux·运维·centos
软件黑马王子17 小时前
Windows 系统下用 VMware 安装 CentOS 7 虚拟机超详细教程(包含VMware和镜像安装包)
linux·windows·centos
IT界刘德华19 小时前
Apache Flink 实战:实时流处理的最佳实践与生产级实现
大数据·flink·apache
YZF_Kevin1 天前
centos安装dashboard详细步骤
linux·运维·centos