Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm competent at the basics of Apache, PHP and virtual hosting but have a question about virtual hosting. As far as I'm aware, HOSTS files can only be in one of the following locations:

C:/Windows/system32/drivers/etc (varies in older installs, I believe)

I don't think it can be put elsewhere for use with Apache, simply for virtual hosts, and the main HOSTS file for blocking sites etc.

I heard about PAC files on Uniform Server's website (http://wiki.uniformserver.com/index.php/Virtual_Hosting:_PAC) but they're browser-specific though, aren't they?

What's the best way to deal with virtualhosts, other than HOSTS file?

My server isn't currently open to the internet yet, but if it is, what's the best way to resolve DNS for my virtualhost domains if it were to become forward-facing (i.e open to the internet)?

share|improve this question
add comment

2 Answers

The virtualhosts in Apache are a separate concept from the etc/hosts file. The etc/hosts file is just a method of local DNS resolution. Virtualhosts are a configuration option where Apache will give a different page depending on what the requested URL is. This requires some DNS magic, since the end user needs to be able to resolve the host names. Multiple IPs or ports are two other options.

In DNS, you'd just add an entry for a different domain, pointing at the same IP. For example, www.site1.com and www.site2.com would both point to 172.32.4.6

More info on how VirtualHosts work is available here: http://httpd.apache.org/docs/current/vhosts/

share|improve this answer
add comment

Some mixed-up terminology, here. The "hosts" in the hosts file refer to statically defined name-to-number address definitions. So, for example, you'll see a line in there that defines localhost as 127.0.0.1 (and possibly ::1, depending on windows version).

The VirtualHosts in apache, on the other hand, refer to a configuration method in Apache where you serve up different web pages depending on the properties of the incoming request; notably, the port that the connection comes in on and the Host header attached to the request.

In this way, an Apache configuration can, for instance, serve up a separate set of pages for multiple different domains; for instance, serving up a different group of pages when www.domain.com is requested versus when info.domain.com is requested. Apache's documentation is a good overview on VirtuaHosts.

Hope this helps to clear things up.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.