Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How shared hostings, domain names and DNS work together?

I 've this little doubt but I couldn't find information about it, probably because I'm not searching the correct thing.

When a browser ask for "www.mydomain.com", the DNS server returns an IP Address, then the browser go there... but what does happen then? I mean, that IP address could be a shared hosting that contains hundreds of web pages and domains, so how does it knows where it have to go?

Is something that the web server does? is it something that I could implement in a web application?

I mean, for example I have a web application that contains accounts, and each account has a default web page. You could access that page passing the account namne, for example "www.mydomain.com/myaccount", but now I want to register "www.myaccount.com" and then it will get the "www.mydomain.com/myaccount" content. Is it possible?

Kind regards.

like image 384
vtortola Avatar asked May 06 '10 23:05

vtortola


2 Answers

HTTP/1.1 requires that all requests include a Host header which includes the domain name that you typed in. So a basic request for "http://www.example.com/foo/bar.html" will look like this:

GET /foo/bar.html HTTP/1.1
Host: www.example.com

And the web server will then be able to use the Host header to route the request to the correct website, even if there's more than one on the same IP address.

like image 112
Dean Harding Avatar answered Oct 12 '22 01:10

Dean Harding


The webserver handles which application responds to your request. Your "shared hosting" has another name. It's called "virtual hosts". The webserver has a list of "virtual hosts" and depending on how you got to the host (via what hostname), the web server picks which application responds to your request.

like image 40
dlamotte Avatar answered Oct 11 '22 23:10

dlamotte