shorter answer - through HTTP Headers
long answer - HTTP stands for "Hypertext Transfer Protocol". HTTP headers are the core part of these HTTP requests and responses, and they carry information about the client browser, the requested page, the server and more.When you type a url in your address bar, your browser sends an HTTP request and it may look like this:
GET /test.html HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
As mentioned above, browser sends Host as 127.0.0.1 and User Agent as Mozilla. So by reading these HTTP headers value, Web server finds the server and browser name.
~ abhay