LInux基础--apache部署网站

发布于:2025-03-17 ⋅ 阅读:(16) ⋅ 点赞:(0)

httpd的安装

yum -y install httpd

httpd的使用

启动httpd

systemctl enable --now httpd

使用enable --now 进行系统设置时,会将该服务设置为开机自启并且同时开启服务

访问httpd

创建虚拟主机

基于域名

在一台主机上配置两个服务server1和server2,其中服务server1的域名为monkey,服务服务server2的域名为apple

资源表-1
服务 域名
server1 www.aaa.com
server2 www.bbb.com

配置server1

<VirtualHost *:80>
DocumentRoot /var/www/monkey
ServerName www.aaa.com
<Directory /var/www/monkey>
AllowOverride none
Require all granted
</Directory>
</VirtualHost>

配置server2

<VirtualHost *:80>
DocumentRoot /var/www/apple
ServerName www.bbb.com
<Directory /var/www/apple>
Require all granted
AllowOverride none
</Directory>
</VirtualHost>

配置本地dns解析

验证结果

基于IP地址

资源表-2
服务 IP地址
server1 192.168.211.205
server2 192.168.211.222

为主机添加IP地址

修改配置文件

配置server1

<VirtualHost 192.168.211.205:80>
DocumentRoot /var/www/monkey
<Directory /var/www/monkey>
Require all granted
AllowOverride none
</Directory>
</VirtualHost>

配置server1

<VirtualHost 192.168.211.222:80>
DocumentRoot /var/www/apple
<Directory /var/www/apple>
Require all granted
AllowOverride none
</Directory>
</VirtualHost>

验证结果

基于端口号

资源表-3

服务

端口
server1 80
server2 81

配置文件

配置server1

<VirtualHost *:80>
DocumentRoot /var/www/monkey
<Directory /var/www/monkey >
Require all granted
AllowOverride none
</Directory>
</VirtualHost>

配置server2

<VirtualHost *:81>
DocumentRoot /var/www/apple
<Directory /var/www/apple>
Require all granted
AllowOverride none
</Directory>
</VirtualHost>

验证结果