15-02-07 - Virtual hosting, how it works ?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

15-02-07 - Virtual hosting, how it works ?

Postby kawa78 » 07. February 2015 15:38

Hello,

I'm struggling with Proxy, host, httd.conf and httd_vhosts.conf and need some help to understand how it is supposed to work in my specific implementation.

First, let me try to explain what I'm trying to do.

I want to install a websimulator intended to be implemented on a server that is not connected to the internet. The user are using WS7 PCs connected to a WS7 server via a local network (workgroup or domestic network) or via a client WS of a Windows terminal server.

The simulator includes a copy of 150 different web sites, some of them dynamic (i.e with sql tables) and some of them static. The "index page" is a list of site categories, each item in a site category list includes the hyper link to the site e.g : http://www.example1.org. The corresponding site is stored in a directory : /xampp/htdocs/WebSimulator/example1

Let's examine the second implementation (WS terminal Server). In this implementation, I have set the following :
  • hosts : 127.0.0.1 localhost
  • httd.conf :
    • ServerRoot "C:/xampp/apache"
    • Listen 127.0.0.1:80
    • ServerName WebSimulator
    • DocumentRoot "C:/xampp/htdocs" <Directory "C:/xampp/htdocs">
    • <Directory "C:/xampp/cgi-bin"> AllowOverride All Options None Require all granted </Directory>
    • Include conf/extra/httpd-vhosts.conf
  • httpd-vhosts.conf :
    • <VirtualHost localhost:80>
      ServerName localhost
      DocumentRoot "c:/xampp/htdocs/"
      </VirtualHost>
    • <VirtualHost *:80>
      DocumentRoot "c:/xampp/htdocs/XebSimulator/example1"
      ServerName www.example1.org
      </VirtualHost>

Unfortunately, I have observed that the "virtual hosts" directives are ineffective unless I add "127.0.0.1 www.example1.org" line in the host file.

My question is quite simple : is it mandatory to have a specific redirection line in the hosts file for each "virtual host" that I have to address on my server ?

Thanks in advance for your help.
PS : the other implementation is only different in the sense that I have to remplace 127.0.0.1 by the IP address of the server (or name in the workgroup) and have a the client browser connect thru a proxy file that give the server IP or logical address
kawa78
 
Posts: 2
Joined: 07. February 2015 14:47
Operating System: windows 7 pro

Re: 15-02-07 - Virtual hosting, how it works ?

Postby gsmith » 07. February 2015 18:54

kawa78 wrote:is it mandatory to have a specific redirection line in the hosts file for each "virtual host" that I have to address on my server ?

Unless it's a real actual domain name (like for example http://www.apachefriends.org) then yes.

But look at http://www.apachefriends.org, if in a command prompt window you type;
nslookup http://www.apachefriends.org
What does it answer with, an IP address. Since http://www.example1.org is not a fully qualified domain name, you use the hosts file in Windows to trick your computer into thinking it is.
gsmith
 
Posts: 278
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win 10/2012R VS 14,15,16

Re: 15-02-07 - Virtual hosting, how it works ?

Postby Nobbie » 07. February 2015 19:21

kawa78 wrote:My question is quite simple : is it mandatory to have a specific redirection line in the hosts file for each "virtual host" that I have to address on my server ?


Let me ask vice verse: forget about Apache etc., how should a browser (or any other client) know, which IP is assigned to "www.example.org" (or for example www.google.com etc.). First of all, domain names are strings without any meaning, only strings, nothing else, like a family name as "Miller" or so - if you enter a domain name into a browser, which server (worldwide!) is adressed by that "string"?
Nobbie
 
Posts: 13175
Joined: 09. March 2008 13:04

Re: 15-02-07 - Virtual hosting, how it works ?

Postby gsmith » 07. February 2015 20:58

Heh heh, to take Nobbie's point further, the network protocol in use here is TCP/IP, not TCP/Domain. The computers only understand IP addresses, not domain names. Humans on the other hand are much better at remembering domain names than a sites IP address. This is why we have DNS, and it's main purpose is to tell your computer what IP corresponds to any particular domain name. It also as you can see using virtual hosts allows a single server to have more that one distinct site on a single IP address.
gsmith
 
Posts: 278
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win 10/2012R VS 14,15,16

Re: 15-02-07 - Virtual hosting, how it works ?

Postby kawa78 » 08. February 2015 10:18

Thanks to gsmith (and also Nobbie) for your answer :) . Its clear and confirms what I have observed during all the tests I have made.

To summerize :
  • Since I'm not using a "real" domain (i.e a domain that is registered in a DNS on the internet), I have to give the IP address in the host file,
  • the added value of the vhost in Apache is :
    • to let you have several "sites" on your server,
    • tell Apache where to find the data related to each "site"
Regards
kawa78
 
Posts: 2
Joined: 07. February 2015 14:47
Operating System: windows 7 pro

Re: 15-02-07 - Virtual hosting, how it works ?

Postby Nobbie » 08. February 2015 12:51

kawa78 wrote:Since I'm not using a "real" domain (i.e a domain that is registered in a DNS on the internet), I have to give the IP address in the host file,


Basically "yes", but you may also specify a local IP in the hosts file, even if the domain is registered in a DNS. This overrides the DNS value (but of course only locally for that PC), this can be a very usefull feature if you (for example) like to develop or test a project (even wordpress or joomla) locally and you want to match the real life as close as possible by simulating the real domain locally on your PC. Keep in mind, if you do so, that this PC cannot reach the real domain as long as you have it in your hosts file.
Nobbie
 
Posts: 13175
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 190 guests