-2

I would like to understand the need for ServerName in apache.

Lets say that I have a web site with IP 12.13.14.15.

In DNS zone I call it example.com and refer the Ip to it with an A record.

Why isn't this enough? It tells the www that whenever anyone writes example.com, it needs to go to 12.13.14.15 ip.

So why do I need to set it also in apache with NameServer attribute?

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
Noam B.
  • 119
  • 3
  • 7

1 Answers1

4

You don't need to use it, but it allows you to have multiple virtual hosts with different server names to listen on the same IP address.

In the early days of the web, before HTTP/1.1 was introduced, you only could host one domain on any IP address, as there was no way to differentiate the domains. HTTP/1.1 added the Host header that told the server which domain the client wants to talk to and the ServerName tells Apache for which domains the current virtual host should answer.

http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html

Sven
  • 97,248
  • 13
  • 177
  • 225