Apache - virtual hosts

For quick answers to quick questions on whatever subject you need!

Moderator: Thought Police

Locked
Kajun
World Controller
World Controller
Posts: 10412
Joined: Tue Jan 22, 2002 12:00 am
Location: Hear.
Contact:

Apache - virtual hosts

Post by Kajun »

Hey,

Is there a quick answer to being able to construct multiple virtual localhosts given a particular directory using apache?

i.e. rather than having to change httpd.conf every time I want to work on a different site (since they all use /, they need to be set as DocumentRoot

I'd like some way of them retaining the qualities of root, but allowing apache to run all the time while serving all sites.

Got me?
Kajun is awaiting approval.
Kajun
World Controller
World Controller
Posts: 10412
Joined: Tue Jan 22, 2002 12:00 am
Location: Hear.
Contact:

Post by Kajun »

Oh aye, it's just a local setup. I don't have DNS capabilities etc. to map to different IPs/names.

The alternative is to setup some shortcuts to launch apache using different .conf files, but that seems a little OTT?
Kajun is awaiting approval.
Hanohtep
Beth Orton's Mum
Beth Orton's Mum
Posts: 5129
Joined: Sat Feb 02, 2002 12:00 am
Location: Down in a hole.
Contact:

Post by Hanohtep »

You've got to love how Kajun always answers his own questions.
Image
hanohtep is saying is that the material world doesn't work that way
"Goat Boy is here to please you..."
Kajun
World Controller
World Controller
Posts: 10412
Joined: Tue Jan 22, 2002 12:00 am
Location: Hear.
Contact:

Post by Kajun »

Nein! "Oh aye" is to indicate, "And yes, I did forget to add the following, which may aid you in your quest:"
Kajun is awaiting approval.
Kajun
World Controller
World Controller
Posts: 10412
Joined: Tue Jan 22, 2002 12:00 am
Location: Hear.
Contact:

Post by Kajun »

Got there in the end.

Two real solutions:

a) set 'NameVirtualHost 127.0.0.1', setup up lots of VirtualHosts to correspond and give them ServerName.s, then map the same names to 127.0.0.1 in your Hosts file. (more info).
b) run multiple instances of apache specifying a different config file each time using the '-f' CLI parameter. Set each 'site' to a different port and remember which is which.

There are advantages to each - the first is perfect for a non-hotdesking setup where you just use one machine, i.e. my home one. The second is perfect to stick on my keys and carry around, because otherwise you have to modify the HOSTS file on every machine: with the keys I can just run multiple instances (or more usually, just the one I'm developing).

Excellent piece of software; terrible piece of documentation. :lol:
Kajun is awaiting approval.
Locked