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

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

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是在 CentOS 8 上配置基于域名访问的 web 服务器的步骤: 1. 安装 Apache 在终端中输入以下命令安装 Apache: ``` sudo dnf install httpd ``` 2. 启动 Apache 安装完成后,输入以下命令启动 Apache: ``` sudo systemctl start httpd ``` 3. 设置开机自启 为了确保每次开机都能自动启动 Apache,输入以下命令: ``` sudo systemctl enable httpd ``` 4. 配置防火墙 如果您的 CentOS 8 上开启了防火墙,需要开启 HTTP 和 HTTPS 服务,输入以下命令: ``` sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload ``` 5. 配置虚拟主机 在 Apache配置文件中添加虚拟主机配置。在终端中输入以下命令编辑 Apache配置文件: ``` sudo vi /etc/httpd/conf/httpd.conf ``` 在文件末尾添加以下内容: ```apache <VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined </VirtualHost> ``` 其中,`example.com` 和 `www.example.com` 分别是您的域名和子域名,`/var/www/example.com` 是您网站的根目录。 6. 创建网站目录 在终端中输入以下命令创建网站根目录: ``` sudo mkdir /var/www/example.com ``` 7. 创建网页 在 `/var/www/example.com` 目录下创建一个名为 `index.html` 的文件,输入以下命令: ``` sudo vi /var/www/example.com/index.html ``` 在文件中输入以下内容: ```html <!DOCTYPE html> <html> <head> <title>My Website</title> </head> <body> <h1>Welcome to My Website</h1> <p>This is my first web page.</p> </body> </html> ``` 保存并退出文件。 8. 重启 Apache 在完成上述步骤后,需要重启 Apache 使配置生效,输入以下命令: ``` sudo systemctl restart httpd ``` 9. 修改 hosts 文件 在客户端电脑的 hosts 文件中添加以下内容: ``` your_server_ip example.com your_server_ip www.example.com ``` 将 `your_server_ip` 替换为您的服务器 IP 地址。 10. 访问网页 在浏览器中输入您的域名或子域名,您应该能够看到您创建的网页。 希望这些步骤能够帮助您在 CentOS 8 上配置基于域名访问的 web 服务器。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值