简体   繁体   中英

What is the correct way to use wildcard DNS?

I need the apache virtualhost follow the following rule:

1- If domain.com or www.domain.com then show contents in /var/www/domain.com/home

2- If blog.domain.com then show contents in /var/www/domain.com/blog

3- If is a wildcard(*) then show contents in /var/www/domain.com/platform

To make this possible I edited my virtualhost as follows:

ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html/home

ServerName domain.com
ServerAlias blog.domain.com
DocumentRoot /var/www/domain.com/public_html/blog

ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domain.com/public_html/plataforma

DNS ZONE:

@ IN A 111.111.1.111

(*) CNAME @

Doubt:

The way I did is a good practice? If not, how about it? Do I need to create a record in the DNS zone for the www and blog ?

You don't have to create a record in your DNS as long as you have a *.domain.tld entry that points to the correct server and as long as all 3 websites are running on the same host. if at one point you want to move on and migrate one of these website to a different server you will have to add this particular subdomain to the DNS.

I think overall this is not a very bad setup but i am unsure if the ServerName value for the second and third website should be different from the first one. May you should use the Alias as ServerName and get totally rid of the Alias in the second and third entry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM