基于端口的实现
[root@localhost httpd]# cat conf.d/test.conf
<VirtualHost *:80>
DocumentRoot /data/html/a
<Directory "/data/html/a">
Options none
Allowoverride none
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot /data/html/b
<Directory "/data/html/b">
Options none
Allowoverride none
Require all granted
</Directory>
</VirtualHost>
基于主机名的访问
[root@localhost httpd]# cat conf.d/test.conf
<VirtualHost *:80>
DocumentRoot "/data/html/a"
ServerName "www.a.com"
<Directory "/data/html/a">
Options none
Allowoverride none
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/html/b"
ServerName "www.b.com"
<Directory "/data/html/b">
Options none
Allowoverride none
Require all granted
</Directory>
</VirtualHost>
基于ip地址的访问
[root@localhost httpd]# cat conf.d/test.conf
<VirtualHost 192.168.199.243:80>
DocumentRoot "/data/html/a"
ServerName "www.a.com"
<Directory "/data/html/a">
Options none
Allowoverride none
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.192.128:80>
DocumentRoot "/data/html/b"
ServerName "www.b.com"
<Directory "/data/html/b">
Options none
Allowoverride none
Require all granted
</Directory>
</VirtualHost>