Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

named virtual hosts for different domain names

Status
Not open for further replies.

gfunk123

IS-IT--Management
May 22, 2001
143
GB
Is there any way i can for example have 2 domains registered ie


with the DNS records pointing to the same IP address (my linux apache server) and have apache determine which document root to point it too. I read a bit on named virtual hosts but it only referred to situations where you have for example


ie, a sub domain

If I can do this, how does it work, because as i understand it, DNS names get resolved to IPs before they physically get to the web server and thus how would it detemine which domain name the http packet was destined for? I would obviously love to be told that im talking rubbish

any help would be greatly appreciated
cheers
 
When using named virtual hosts, Apache uses the [tt]Host[/tt] header that any HTTP/1.1 complaint browser sends. And the same principle applies when using different domains as when using subdomains. //Daniel
 
You're right. The FQDN gets converted to an IP address by DNS before your browser ever connects to the server. But you're not taking into account higher-level protocols.

The HTTP 1.1 specification provides for the ability of a browser to report to the server the name of the host to which the browser expects to connect.

If you are pointing to then your browser will send the following headers (among others):

GET / HTTP/1.1
Host:

Your Apache server can then match the value sent by the "Host:" header to a name given in a ServerName or ServerAlias directive


This works for HTTP, but HTTPS is still problematic. Since the server chooses an SSL certificate to use before any HTTP headers are sent, you can't share an IP address across HTTPS connection spanning multiple domains.

Want the best answers? Ask the best questions: TANSTAAFL!
 
You can have as many domains as you want pointing to the same ip address. Apache will sort it out as danielhozac and sleipnir214 have stated above. Create a vhost container for each domain and use the ServerName directive for each one. There should be an example vhost container in your httpd.conf file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top