虚拟主机的配置在apache安装目录下/conf/extra/httpd-vhosts.conf文件中,需要在/conf/httpd.conf中开启。
LoadModule vhost_alias_module modules/mod_vhost_alias.soInclude conf/extra/httpd-vhosts.conf
1、基于IP地址的虚拟主机 (*服务器有多个IP地址)
DocumentRoot D:/wwwroot/site1 ServerName www.site1.com Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All DocumentRoot D:/wwwroot/site2 ServerName www.site2.com Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All
2、基于IP地址和多端口 (*分别绑定8080和8088端口)
Listen 127.0.0.1:8080DocumentRoot D:/wwwroot/site1 ServerName www.site1.com Listen 127.0.0.1:8088DocumentRoot D:/wwwroot/site2 ServerName www.site2.com
3、单IP地址基于域名的虚拟主机
Listen 80NameVirtualHost *:80DocumentRoot D:/wwwroot/site1 ServerName www.site1.com DocumentRoot D:/wwwroot/site2 ServerName www.site2.com
4、多IP地址基于域名的虚拟主机
DocumentRoot D:/wwwroot/site1 ServerName www.site1.com DocumentRoot D:/wwwroot/site2 ServerName www.site2.com
5、多端口配置基于域名的虚拟主机
Listen 80DocumentRoot D:/wwwroot/site1 ServerName www.site1.com Listen 8080DocumentRoot D:/wwwroot/site2 ServerName www.site2.com
6、基于域名和基于IP 的混合虚拟主机
Listen 80NameVirtualHost 192.168.1.1DocumentRoot D:/wwwroot/site1 ServerName www.site1.com Listen 8080DocumentRoot D:/wwwroot/site2 ServerName www.site2.com