《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
相关推荐
魏波.28 分钟前
Apache Shiro“全栈式安全框架”简述
apache·shiro
坐望云起7 小时前
Hyper-V + Centos stream 9 搭建K8s集群(二)
linux·kubernetes·centos
先鱼鲨生19 小时前
gtest框架的安装与使用
开发语言·apache
caz2821 小时前
麒麟服务器版操作系统添加VNC
linux·服务器·centos·vnc
IT小辉同学21 小时前
CentOS 7 编译 Redis 6.x 完整教程(解决 GCC 版本不支持 C11)
linux·redis·centos
坐望云起1 天前
Hyper-V + Centos stream 9 搭建K8s集群(一)
linux·kubernetes·centos
来自于狂人2 天前
CentOS 镜像源配置与 EOL 后的应对策略
linux·运维·centos
Apache Flink2 天前
Apache Flink 2.1.0: 面向实时 Data + AI 全面升级,开启智能流处理新纪元
人工智能·flink·apache
光军oi2 天前
Javaweb————Apache Tomcat服务器介绍及Windows,Linux,MAC三种系统搭建Apache Tomcat
服务器·tomcat·apache