Apache优化之虚拟主机(基于IP的虚拟主机)

Apache优化之虚拟主机(基于IP的虚拟主机)

前言

刚刚我们写了虚拟主机(基于端口的虚拟主机),接下来我们来尝试做一下虚拟主机(基于IP地址的虚拟主机)。

实验步骤

1.实验分析

既然是基于ip的虚拟主机,我们需要不同的IP地址,虚拟机默认是装一块网卡,所以我们需要在虚拟机中再添加一块网卡

2.添加一块网卡

在这里插入图片描述

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

3.对虚拟主机配置文件进行配置

[root@localhost conf]# cd /etc/httpd/conf/extra/
[root@localhost extra]# vim vhosts.conf
<VirtualHost 192.168.73.143:80>
    DocumentRoot "/var/www/html/hello"
    ErrorLog "logs/www.hello.com.error_log"
    CustomLog "logs/www.hello.com.access_log" common
    <Directory "/var/www/html/">
    Require all granted
    </Directory>
</VirtualHost>

<VirtualHost 192.168.73.154:80>
    DocumentRoot "/var/www/html/hello02"
    ErrorLog "logs/www.hello02.com.error_log"
    CustomLog "logs/www.hello02.com.access_log" common
    <Directory "/var/www/html/">
    Require all granted
    </Directory>
</VirtualHost>

#<VirtualHost *:80>
#    DocumentRoot "/var/www/html/world"
#    ServerName www.world.com
#    ErrorLog "logs/www.world.com.error_log"
#    CustomLog "logs/www.world.com.access_log" common
#    <Directory "/var/www/html/">
#    Require all granted
#    </Directory>
#</VirtualHost>
#
#<VirtualHost *:8080>
#    DocumentRoot "/var/www/html/world02"
#    ServerName www.world.com
#    ErrorLog "logs/www.world02.com.error_log"
#    CustomLog "logs/www.world02.com.access_log" common
#    <Directory "/var/www/html/">
#    Require all granted
#    </Directory>
#</VirtualHost>

4.去站点目录下添加站点

[root@localhost extra]# cd /var/www/html/
[root@localhost html]# ls
hello  world  world02
[root@localhost html]# mkdir hello02
[root@localhost html]# echo "this is hello02 web" >> hello02/index.html

5.给httpd主配置文件进行配置

[root@localhost html]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf 
Listen 192.168.73.143:80
Listen 192.168.73.154:80
#Listen 80
[root@localhost conf]# systemctl restart httpd
[root@localhost conf]# netstat -ntap | grep 80
tcp        0      0 192.168.73.154:80       0.0.0.0:*               LISTEN      2989/httpd          
tcp        0      0 192.168.73.143:80       0.0.0.0:*               LISTEN      2989/httpd

6.在win10主机里面进行测试

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值