开启模块支持
LoadModule vhost_alias_module modules/mod_vhost_alias.so
基于域名的虚拟目录设计
注:低版本可能需要 配置项中 NameVirtualHost *:80 的支持
#匹配localhost访问的地址
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\www"
<Directory "D:\www">
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.html index.php default.php
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
#匹配test1.domain.site访问的地址
<VirtualHost *:80>
ServerName test1.domain.site
DocumentRoot "D:\www\test1"
<Directory "D:\www\test1">
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.html index.php default.php
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
#匹配test2.domain.site访问的地址
<VirtualHost *:80>
ServerName test1.domain.site
DocumentRoot "D:\www\test2"
<Directory "D:\www\test2">
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.html index.php default.php
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
127.0.0.1 localhost
127.0.0.1 test1.domain.site
127.0.0.1 test2.domain.site
基于端口的虚拟目录配置
Listen 8080
<VirtualHost *:8080>
ServerName localhost
DocumentRoot "D:\www"
<Directory "D:\www">
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.html index.php default.php
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
Listen 8081
<VirtualHost *:8081>
ServerName localhost
DocumentRoot "D:\www\test1"
<Directory "D:\www\test1">
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.html index.php default.php
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
Listen 8082
<VirtualHost *:8082>
ServerName localhost
DocumentRoot "D:\www\test2"
<Directory "D:\www\test2">
Options FollowSymLinks IncludesNOEXEC Indexes
DirectoryIndex index.html index.php default.php
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>