0

I'm setting up named virtual host configurations for a domain e.g. www.examplesite.uk

Which of the below name & alias definitions would be preferable? Is there a difference? I've seen various examples online where it's both ways round.

ServerName www.examplesite.uk
ServerAlias examplesite.uk

or

ServerName examplesite.uk
ServerAlias www.examplesite.uk

or just

ServerName www.examplesite.uk

Thank you.

SB_77
  • 11
  • 5

1 Answers1

1

The difference is subtle. As described in Documentation ServerName shows the hostname and port the server uses to identify itself while ServerAlias gives alternate names for a host used when matching requests to name-virtual hosts.

In name-based virtual hosts the hostname is specified by the request's Host header.

Using http://www.example.com to open a website results in 'www.example.com' as Host header. Using http://example.com results in 'exmaple.com' as Host header.

Hence, to cover both ways the common practice is:

ServerName example.com
ServerAlias www.example.com

If you put ServerName www.examplesite.uk and Host header is 'examplesite.uk' Apache will check for matches with other VHs if there are any. If none Apache will use the first VH. So, your last option might not retrieve the webpage you want.

You can also check: What is the difference between ServerName and ServerAlias in apache2 configuration?

Mihail Panayotov
  • 320
  • 2
  • 11