Monday, February 27, 2017

apache2 - why do we have to use ServerName for our websites in apache?





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?


Answer




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


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...