Search code examples
apachednssubdomainapache2.4

Dynamic configuration of subdomains in apache2


Hellow here, needing some guidance and advice !

I know there is already a lot of answers on this subject, and believe me, I searched and read for a long time about it, but I still don't get how to do it. So here is my situation:

I have several websites (A LOT actually, with random names, not really random but I do not decide there names) which are in the folder www of Wamp, like this:

- www
    |-ParentFolder1
    |    |-website1
    |    |-namerandom1
    |    |-anotherrandomname1
    |    |- ....... etc
    |
    |-ParentFolder2
    |    |-website2
    |    |-namerandom2
    |    |-anotherrandomname2
    |    |- ....... etc
    |

I have 2 domain.tld defined and configured on the server (I did not configure it, someone else on my company did it)

And I need to make every websites work with the domain name like that:

website1.domain1.tld
namerandom1.domain1.tld
anotherrandomname1.domain1.tld
... etc


website2.domain2.tld
namerandom2.domain2.tld
anotherrandomname2.domain2.tld
...

I am completely lost, I don't know where and how to begin

Anyway.

With everything I read about the subject of subdomain, I think that I need to make it work by the VirtualHost configuration of Apache2... But I don't know how to manage the fact that the name of the websites are dynamic... And also, do I need to configure a CNAM on the DNS file ? (subdomain) Or VirtualHost is enough ?

Any help would be appreciated, thank you for you time


Solution

  • It's a basic VirtualDocumentRoot configuration of mod_vhost_alias.

    This lets you map hostnames not known in advance into the filesystem using patterns and replacements.

    Your domains are not usable by end users if they're not in DNS. httpd config only kicks in once a client request ends up resolving to an IP address on your server.