前提环境安装
yum -y install httpd*
配置虚拟网卡
ip add#查看原网卡
ifconfig ens33:1 172.16.70.101/24 #添加三块虚拟网卡
ifconfig ens33:2 172.16.70.102/24 #添加三块虚拟网卡
ifconfig ens33:3 172.16.70.103/24 #添加三块虚拟网卡
方法2
cd /etc/sysconfig/network-scripts
cp ifcfg-ens33 ifcfg-ens33:1
vi ifcfg-ens33:1
DEVICE=ens33:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.70.101
NETMASK=255.255.255.0
同样方法创建三个
cp ifcfg-ens33:1 ifcfg-ens33:2
cp ifcfg-ens33:1 ifcfg-ens33:3
ip地址自己行修改
ifdown ens33 #重启网卡
ifup ens33
配置主机host文件,进行测试
vi /etc/hosts
echo “172.16.70.101 test101.com” >> /etc/hosts
echo “172.16.70.102 test102.com” >> /etc/hosts
echo “172.16.70.103 test103.com” >> /etc/hosts
vi /etc/hosts #查看是否追加成功
建立虚拟主机存放网站的根目录
cd /
mkdir www
cd www
mkdir 101
mkdir 102
mkdir 103
写入网站首页的内容
echo "<h1>172.16.70.101</h1>" > 101/index.html
echo "<h1>172.16.70.102</h1>" > 102/index.html
echo "<h1>172.16.70.103</h1>" > 103/index.html
修改httpd.conf配置文件
find / -name httpd.conf
vi /etc/httpd/conf/httpd.conf
在文件末尾加入
Listen 172.16.70.101:80
Listen 172.16.70.102:80
Listen 172.16.70.103:80
Include conf/vhost/*.conf #识别改目录下的.conf文件
yy #复制改行
p #粘贴
重要Listen 80 必须注释掉
编辑每个IP的配置文件
cd /etc/httpd/conf
mkdir vhost
cd vhost
vi test101.conf
<VirtualHost 172.16.70.101:80>
ServerName test101.com
DocumentRoot "/www/101"
<Directory "/www/101/">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
启动服务
systemctl start httpd.service
iptables -F #清除防火墙缓存