Forum Moderators: phranque

Message Too Old, No Replies

setting up local virtual hosts

         

mack

1:46 pm on Mar 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I have quite a lot of experience setting up virtual hosts on Apache, but let's say I want virtual hosting enabled on a local machine running Linux/Apache2. would I simply add the site name to the hosts file, and create a new entry within sites enabled.

then for example typing mack In the adddress bar will resolve to the WWW root as specified in the sites enabled file for the site called mack.

all requests will be internal, so that's why I assume I will need to use the hosts file.

thanks in advance.

Mack.

lammert

7:51 pm on Mar 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yep, this is how it should work. Connecting to a website is a process with two stages. In the first stage the name of the domain is queried against a domain name resolver to give you the IP address where the site can be found. This resolver can be a full featured DNS server, but also the local hosts file. In most configurations the local hosts file takes precedence over a remote DNS server. The following line will tell the browser that it can find the server at the machine with IP address 10.11.12.13. If the browser and Apache server are on the same computer, you could also use IP address 127.0.0.1 here.

10.11.12.13 mack

The second stage is that Apache receives a request on its local IP address from the browser and has to determine from which virtual host to serve. It uses the info in the HTTP headers for this. This virtual host is setup as usual, either with a control panel, or by directly adding the info with a text editor in the httpd.conf configuration file. Be sure that either the ServerName, or a ServerAlias tag of the virtual host matches "mack".

mack

12:21 am on Mar 27, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Thanks lammert, got it working. I think i'm just so used to having a lan server where you can just set up a user per website then go
ip.add.re.ss~user

Thanks for the clarification about doing it locally.

Mack.