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主机里面进行测试