如何创建像* .example.com这样的动态虚拟主机?

时间:2017-05-28 09:03:11

标签: php apache xampp virtual-hosts hosts-file

其中*对于每个客户端都不同,例如apple.example.com,pearl.example.com。 这些都应该路由到相同的IP和相同的目录。 如何修改hosts文件和httpd配置?

更详细的例子:

<VirtualHost 111.22.33.44>
    ServerName                 customer-1.example.com
    DocumentRoot        "/www/hosts/example.com/docs"
    ScriptAlias  "/cgi-bin/"  "/www/hosts/example.com/cgi-bin"
</VirtualHost>

<VirtualHost 111.22.33.44>
    ServerName                 customer-2.example.com
    DocumentRoot        "/www/hosts/example.com/docs"
    ScriptAlias  "/cgi-bin/"  "/www/hosts/example.com/cgi-bin"
</VirtualHost>

<VirtualHost 111.22.33.44>
    ServerName                 customer-N.example.com
    DocumentRoot        "/www/hosts/example.com/docs"
    ScriptAlias  "/cgi-bin/"  "/www/hosts/example.com/cgi-bin"
</VirtualHost>

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在 ServerAlias 中使用星标,如下所示:

<VirtualHost 111.22.33.44>
    ServerName      customer-1.example.com
    ServerAlias     *.example.com
    DocumentRoot    "/www/hosts/example.com/docs"
    ScriptAlias     "/cgi-bin/"  "/www/hosts/example.com/cgi-bin"
</VirtualHost>