Return-Path: Delivered-To: apmail-httpd-users-archive@www.apache.org Received: (qmail 96118 invoked from network); 24 Nov 2009 20:22:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Nov 2009 20:22:19 -0000 Received: (qmail 58350 invoked by uid 500); 24 Nov 2009 20:22:16 -0000 Delivered-To: apmail-httpd-users-archive@httpd.apache.org Received: (qmail 58317 invoked by uid 500); 24 Nov 2009 20:22:16 -0000 Mailing-List: contact users-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: users@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@httpd.apache.org Received: (qmail 58308 invoked by uid 99); 24 Nov 2009 20:22:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Nov 2009 20:22:16 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of aw@ice-sa.com designates 212.85.38.228 as permitted sender) Received: from [212.85.38.228] (HELO tor.combios.es) (212.85.38.228) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Nov 2009 20:22:13 +0000 Received: from localhost (localhost [127.0.0.1]) by tor.combios.es (Postfix) with ESMTP id 51C6322608D for ; Tue, 24 Nov 2009 21:21:51 +0100 (CET) Received: from tor.combios.es ([127.0.0.1]) by localhost (tor.combios.es [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gfN2hXNuenaW for ; Tue, 24 Nov 2009 21:21:51 +0100 (CET) Received: from [192.168.245.129] (p549EB2C1.dip0.t-ipconnect.de [84.158.178.193]) by tor.combios.es (Postfix) with ESMTPA id BFC2F226086 for ; Tue, 24 Nov 2009 21:21:50 +0100 (CET) Message-ID: <4B0C404A.1080907@ice-sa.com> Date: Tue, 24 Nov 2009 21:21:30 +0100 From: =?UTF-8?B?QW5kcsOpIFdhcm5pZXI=?= Reply-To: users@httpd.apache.org User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: users@httpd.apache.org References: <110226.25926.qm@web23008.mail.ird.yahoo.com> In-Reply-To: <110226.25926.qm@web23008.mail.ird.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [users@httpd] Testing virtual hosts on a virtual machine Florent Georges wrote: > Hi, > > I am using a virtual box (Ubuntu server 9.10 with VMware Fusion) > to test a web server. No problem to install Apache on this > Ubuntu box, of course. And I can access the default page after > an install by using http://xxx.xxx.xx.xx/ in my browser (on the > host machine.) > > But the web server will use named virtual hosts. I guess that > won't work as the browser won't send the correct domain name. > > Is there any tool to test an Apache instance with virtual hosts > on a virtual machine? Any best practice or advice to follow in > that configuration? > Because the information available when searching for this on Google or on Wikipedia, and even on the Apache website is rather confusing, let me try to give you an explanation of how this stuff really works. It is a bit long, but I believe that if you understand the explanation below, you will never have trouble again with Virtual Hosts. And also a lot less trouble with browsers and http in general. Still with me ? When you ask a browser to access "http://myhost.company.com", what really happens ? 1) the browser asks the local operating system to "translate" the name "myhost.company.com" into an IP address. The operating system, to do that, works in 2 steps : 1.1) the OS looks into the local "hosts" file, to see if it finds a line like aaa.bbbb.ccc.ddd myhost.company.com If it does, then it returns the IP address "aaa.bbbb.ccc.ddd" to the browser, as a translation for the name "myhost.company.com", and it is finished. 1.2) if the above did not work, then the OS will ask, over the network, to a DNS server to do the same translation. The DNS server will look up its own tables, and in the end it can either answer with an IP address, or with "not found". The OS will then pass back this same answer to the browser, and it is finished. (Of course, this supposes that the OS has a working DNS server to talk to, otherwise it will return an error to the browser right away). 2) Now the browser has an answer, which is either a "host not found", or an IP address. 2.1) If it was a "host not found", the browser tells the user and that's it. 2.2) If the browser has received an IP address however, then the process continues. 3) the browser establishes a TCP/IP connection with the received IP address, on port 80. That either works, or doesn't. 3.1) If it doesn't work, the browser sends an error message to the user : cannot connect to "myhost.company.com", and again that's it. (It may fail to work, for example because there is no host at that IP address, or because there is a host, but there is no program there listening to connections on port 80; or for many other reasons). 3.2) If it works, the process continues. (That it works, implies that on the target server there is a process which actually listens to connection requests on port 80, and accepts them. That will generally be a webserver like Apache). 4) the browser, over this now established TCP connection to the server at that IP address:port 80, sends a HTTP request to that server. This HTTP request consists of minimum 2 lines of text, as follows : GET / HTTP/1.1 Host: myhost.company.com The first line indicates, in the middle, what resource the browser wants. In this case, it just wants the default home page, so the resource URL is "/". The second line indicates which "virtual host" the browser wants to talk to, on the target server (with whom it already has a TCP connection). After sending that request, the browser starts waiting for a server answer over that same TCP connection. 5) the receiving Apache HTTP server receives the above request, and looks at the "Host:" line. Now the receiving Apache HTTP server is going to try to "match" this hostname, with the name of one of the VirtualHost's that are defined in its configuration. It either finds a match, or it does not. 5.1) if it does find a match, then it will process this request using the "personality" of the VirtualHost that is defined for that name. 5.2) if it does not find a match, then it will process this request using the personality of the first defined VirtualHost, from top to bottom of the configuration file. (It does not matter in that case if the hostname matches or not, it will use this first VirtualHost as the "default host".) To give you a practical example : Suppose you have a server with an IP address of 192.168.100.100. On that server, you install Apache. In Apache, you define a new (additional) , and you give it the configuration lines ServerName www.google.com # (really, for the example) DocumentRoot /var/www/some-new-dir DirectoryIndex index.html In that new directory /var/www/some-new-dir, place a html page named "index.html", containing a "Hello, I'm Google !" message. And you restart Apache. Then, on your local workstation, edit the "hosts" file (under Windows, this is at c:/windows/system32/drivers/etc/hosts; under Unix/Linux, it is at /etc/hosts). Add the following line to it : 192.168.100.100 www.google.com # (really, for the example) (change the IP address to the real IP of the host running Apache) Then on your local workstation, call up the browser, and enter the URL "http://www.google.com". What happens, is what I described above, in the following sequence : 1), 1.1), 2), 2.2), 3), 3.2), 4), 5), 5.1) Now go back to edit the local hosts file, and comment out the line that you added before. Close the browser, re-open it, and ask again for "http://www.google.com". Obviously, you do not get the same page. Why ? Because this time, what happened is 1), 1.1), 1.2), 2), 2.2), 3), 3.2), 4), 5), 5.1) small difference, big effect. In all the above, there are 2 essential elements : - the local browser must know which IP address corresponds to the name of the virtual host - the Apache server must know that it has a virtual server with that name It does not matter whether the Apache host is a physical machine or a virtual machine. As long as your IP networking setup, and the hostname resolving mechanism (known as "the resolver") are working, it will work. There are no "tricks" involved. It is pure logic at every step. --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See for more info. To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org " from the digest: users-digest-unsubscribe@httpd.apache.org For additional commands, e-mail: users-help@httpd.apache.org