站点标识: socket
IP相同,但端口不同
IP不同,但端口均为默认端口
FQDN不同:请求报文中首部 Host: www.magedu.com
有三种实现方案:
基于ip:为每个虚拟主机准备至少一个ip地址
基于port:为每个虚拟主机使用至少一个独立的port
基于FQDN:为每个虚拟主机使用至少一个FQDN
#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>
root:~ # curl 192.168.64.150:8001
111
root:~ # curl 192.168.64.150:8002
222
ip a a 192.168.36.7 dev ens33
ip a a 192.168.36.8 dev ens33
ip a a 192.168.36.9 dev ens33
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>
root:~ # curl 192.168.36.6
111
root:~ # curl 192.168.36.7
222
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>
在windows编辑 C:\Windows\System32\drivers\etc\hosts #吧只读去掉
192.168.36.7 www.a.com www.b.com www.c.com
原文:https://blog.51cto.com/9019400/2393436