What is the right way to use DNS wildcard?

Asked

Viewed 196 times

4

I need my server’s Apache virtualhost to meet the following rule:

1- If it’s.com or www.domain.com, then display the content in /var/www/domain.com/home

2- If for blog.domain.com, then display the content in /var/www/domain.com/blog

3- If it is a wildcard(*), that is, it is not one of the two above, then it displays the content in /var/www/domain.com/platform

For this to be possible I edited my virtualhost as follows:

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

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

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

And my DNS zone as follows:

@ IN A 111.111.1.111

(*) CNAME @

Doubt:

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

1 answer

0


The DNS part is correct, but the servername are in conflict, I think it should be something like this:

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


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


ServerName plataforma.dominio.com
ServerAlias *.dominio.com
DocumentRoot /var/www/dominio.com/public_html/plataforma
  • I did as you suggested, but why can’t wildcard Servername(*) be the same as the first one? What kind of conflict could occur?

  • 1

    You cannot point the exact same server name to different directories...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.