apache配置基于域名访问

编辑配置文件,注释掉directory文件,一共四个

vim /etc/httpd/conf/httpd.conf

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
然后保存退出
检查一下httpd配置文件,ok正常
在这里插入图片描述
创建虚拟主机,编辑文件路径/etc/httpd/conf.d/a123.conf

cd /etc/httpd/conf.d
vi a123.conf

在这里插入图片描述
然后在a123.conf文件里加入这些东西
在这里插入图片描述
可直接复制进去
其中80是端口
DocumentRoot /mnt/z里的 /mnt/z 是默认主页
1.yao.com 是域名(如何在主机上重定向域名
在这里插入图片描述
在这里我创建了两个页面
<Directory “/mnt/z”>
<Directory “/mnt/z/z”>

<VirtualHost *:80>
		DocumentRoot /mnt/z
		ServerName 1.yao.com
	<Directory "/mnt/z">
		Options Indexes FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
	<Directory "/mnt/z/z">
		Options Indexes FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost>

创建网站根目录和主文件

mkdir -p /mnt/z/z
echo "hello apache" >/mnt/z/index.html
echo "hello z" >/mnt/z/z/index.html

在这里插入图片描述
验证apache配置文件,通过后重启服务

httpd -t && systemctl restart httpd

在这里插入图片描述在这里插入图片描述在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45663905/article/details/107334934
今日推荐