Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ServerName and ServerAlias in apache2 configuration?

Tags:

I am configurating my apache2 server and I wonder whats the difference between ServerName and ServerAlias.

Is the ServerName always a name without www as like google.de and the ServerAlias is www.google.de

Even if it's like this, I don't get it :) sorry.

I am not a professional (now) so thank you for your help! Every help will upvoted immediately.

like image 203
RayofCommand Avatar asked Aug 21 '13 15:08

RayofCommand


People also ask

What is ServerName in Apache configuration?

ServerName - If the host part of the HTTP request matches this name, then allow the request. Normally this would be a domain name that maps to an IP, but in this case the HTTP request host must match this IP. ServerAlias - Alternate names accepted by the server.

What is the difference between name-based virtual hosting and IP-based virtual hosting?

IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve. Therefore you need to have a separate IP address for each host. With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers.

What is Namevirtualhost in Apache?

Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames. Name-based virtual hosting also eases the demand for scarce IP addresses.


1 Answers

From the Documentation:

ServerName: Hostname and port that the server uses to identify itself

ServerAlias: Alternate names for a host used when matching requests to name-virtual hosts

Most people simply use ServerName to set the 'main' address of the website (eg. 'mywebsite.com') and ServerAlias to add additional addresses the website will be bound to (eg. 'www.mywebsite.com').

Yet, there are subtle differences between the two:

  • ServerName can accept port numbers as well, while ServerAlias cannot.
  • ServerAlias can accept wildcards (eg. *.mywebsite.com), while ServerName cannot.

Read the documentation to understand why.

like image 146
haim770 Avatar answered Sep 19 '22 18:09

haim770