《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
相关推荐
zly350014 小时前
CentOS上可以 ping通 IP但不能 ping通域名,ping不通域名
linux·tcp/ip·centos
明天…ling16 小时前
CentOS 7 安装 Docker 踩坑全记录(含 sudo 权限、yum 源失效、命令报错解决方案)
linux·docker·centos
zhangfeng113318 小时前
glibc = GNU C Library (GNU C 标准库)CentOS 7 (glibc 2.17) pip支持
c语言·人工智能·神经网络·机器学习·centos·gnu
oioihoii2 天前
CentOS 7单机部署Elasticsearch:这些坑和关键配置,生产环境踩过才知道
linux·elasticsearch·centos
linksinke2 天前
在 CentOS 7.x 外网环境离线构建便携式 Python 3.11.4 的方案参考
linux·python·centos
大明者省2 天前
CentOS 与 Ubuntu Python 部署差异
笔记·python·ubuntu·centos
linux修理工2 天前
使用 virt-install 命令行快速创建 KVM 虚拟机(以 CentOS 7 为例)
linux·运维·centos
MageGojo2 天前
小程序每日一谜怎么做:riddle 接口接入示例
windows·小程序·apache·谜语
zizle_lin3 天前
CentOS配置yum源
linux·运维·centos
penngo3 天前
FlowLoom:基于 Apache Spark 的可视化数据处理平台
大数据·spark·apache