I need to use Apache to achieve such a config, and I'd like to have some advice.
I have a domain: example.com. We have deployed a website under /var/www/html accessible via www.example.com. In addition, we allow users to sign up and access contents (these users then become our tenants). Such tenant-specific contents are deployed under /var/www/tenants. For each of the tenants, we create a subdomain for them. For example, for tenant A, we create tenanta.example.com. Each time one navigates to that url, he can access some content specific to tenant A.
Now tenant A wants to set up a vanity domain for tenanta.example.com. Say the vanity domain is: help.tenanta.com, where tenanta.com is a domain registered by tenant A. He sets up a CNAME record to point help.tenanta.com to tenanta.example.com.
Now it comes to the Apache part. How do I set up the config file so that a request for help.tenanta.com fetches the content under /var/www/tenants, instead of /var/www/html?
Here is what I tried:
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName www.example.com ServerAlias example.com, cdn.example.com # See: http://stackoverflow.com/questions/2297403/http-host-vs-server-name UseCanonicalName on DocumentRoot /var/www/html <VirtualHost> <VirtualHost *:80> ServerAdmin email@example.com ServerAlias *.example.com UseCanonicalName on DocumentRoot /var/www/tenants <VirtualHost>
But in such a setting, a request to help.tenanta.com still goes to /var/www/html, instead of /var/www/tenants.
Note: similar questions have been asked on serverfault, like: Apache virtual host based on CNAME
,but they don't address the wildcard subdomain issue.