《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
相关推荐
Boop_wu11 小时前
[Java EE] 字符流和字节流实例
java·开发语言·apache
程序员果子13 小时前
零拷贝:程序性能加速的终极奥秘
linux·运维·nginx·macos·缓存·centos
heartbeat..14 小时前
使用 Apache POI 实现 Excel 文件读写(导入 导出)操作的工具类
java·apache·excel·文件
#微爱帮#16 小时前
微爱帮监狱写信寄信小程序PHP高并发优化技术方案
服务器·php·apache
云和数据.ChenGuang16 小时前
运维工程师软件之httpd`(Apache HTTP Server)
运维·http·apache
知识分享小能手17 小时前
CentOS Stream 9入门学习教程,从入门到精通,CentOS Stream 9 进程管理 —语法详解与实战案例(8)
linux·学习·centos
子夜江寒18 小时前
MySQL 安装与配置指南(CentOS 7)
数据库·mysql·centos
哇哈哈&18 小时前
rabbitmq最简单的安装方法
linux·运维·centos
悟能不能悟1 天前
apache配置反向代理
apache
鸠摩智首席音效师1 天前
如何使用 .htaccess 屏蔽 IP 地址 ?
apache