《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
相关推荐
Fireworkitte1 小时前
Ubuntu 和 CentOS 中配置静态 IP
tcp/ip·ubuntu·centos
NEKGod10 小时前
centos9安装显卡驱动
centos·gpu算力
gb421528714 小时前
高性能场景使用Protocol Buffers/Apache Avro进行序列化怎么实现呢
apache
midsummer_woo14 小时前
复现 apache HTTPD 换行解析漏洞(CVE-2017-15715)
web安全·apache
心灵宝贝1 天前
Apache JMeter 2.9使用教程:压力测试入门步骤详解
jmeter·apache·压力测试
(:满天星:)2 天前
ELK技术栈全面解析与部署方案
linux·运维·服务器·elk·docker·centos
vhgcc2 天前
在 Java 中使用 Apache Tika 读取 doc、docx等格式文件内容
java·开发语言·自然语言处理·apache·ai编程
Mrdaliang2 天前
linux防火墙讲解
linux·服务器·apache