您想在 Apache 上进行大规模虚拟主机。在这里您将找到如何执行此操作的信息:
Dynamically configured mass virtual hosting
根据您链接的教程中的示例:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website"
ServerName clientA.local
<Directory "C:\Documents and Settings\Me\My Documents\clientA\website">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\Documents and Settings\Me\My Documents\clientB\website"
ServerName clientB.local
<Directory "C:\Documents and Settings\Me\My Documents\clientB\website">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
关于此配置的问题是,它是静态的,更改时需要重新启动 Apache。
首先,您需要在 DNS 服务器中创建一条记录,以便将所有子域映射到您的服务器。像这样:
*.local. 3600 IN A x.x.x.x
要在 localhost 上进行测试,您可以在 hosts 文件中手动设置一些子域。请参阅 here 为什么无法在 hosts 文件中设置通配符子域。
别忘了在 httpd.conf 中加载 vhost_alias_module:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
然后你将替换你的虚拟主机配置,就像这个例子:
<VirtualHost *>
# get the server name from the Host: header
UseCanonicalName Off
# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon
# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot "C:/Documents and Settings/Me/My Documents/%1/website"
<Directory "C:/Documents and Settings/Me/My Documents/*/website">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
DirectoryIndex index.php index.html index.htm
</Directory>
</VirtualHost>
这将使用通配符来设置请求的子域的文档根目录。