How can I create dynamic virtual hosting like *.example.com?

105 Views Asked by At

Where * is different for each client like apple.example.com, pearl.example.com. These all should be routed to the same IP and same directory. How to modify the hosts file and the httpd config?

More detailed example:

<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>

Thanks!

1

There are 1 best solutions below

3
On BEST ANSWER

You can use star in ServerAlias like this:

<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>