mkdir /data/site{1,2,3}
echo ‘www.a.com‘ > /data/site1/index.html
echo ‘www.b.com‘ > /data/site2/index.html
echo ‘www.c.com‘ > /data/site3/index.html
![]
vim /etc/httpd/conf.d/vhosts.conf
listen 8001
listen 8002
listen 8003
<virtualhost *:8001>
documentroot /data/site1
<directory /data/site1>
require all granted
</directory>
</virtualhost>
<virtualhost *:8002>
<directory /data/site2>
require all granted
</directory>
documentroot /data/site2
</virtualhost>
<virtualhost *:8003>
<directory /data/site3>
require all granted
</directory>
documentroot /data/site3
</virtualhost>
ip a a 192.168.36.8/24 dev eth0
ip a a 192.168.36.9/24 dev eth0
vim /etc/httpd/conf.d/vhosts.conf
<virtualhost 192.168.36.7:80>
documentroot /data/site1
<directory /data/site1>
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.36.8:80>
<directory /data/site2>
require all granted
</directory>
documentroot /data/site2
</virtualhost>
<virtualhost 192.168.36.9:80>
<directory /data/site3>
require all granted
</directory>
documentroot /data/site3
</virtualhost>
vim /etc/httpd/conf.d/vhosts.conf
<virtualhost *:80>
documentroot /data/site1
servername www.a.com
<directory /data/site1>
require all granted
</directory>
CustomLog "logs/a_access_log" combined
</virtualhost>
<virtualhost *:80>
<directory /data/site2>
require all granted
</directory>
documentroot /data/site2
servername www.b.com
CustomLog "logs/b_access_log" combined
</virtualhost>
<virtualhost *:80>
servername www.c.com
<directory /data/site3>
require all granted
</directory>
documentroot /data/site3
CustomLog "logs/c_access_log" combined
</virtualhost>
vim /etc/hosts
192.168.36.7 www.a.com www.b.com www.c.com
原文:https://blog.51cto.com/14234933/2393713