Apache Virtual Hosts file setup.

Heeter

Overclocked Like A Mother
Joined
8 Jul 2002
Messages
2,732
Hi all,

It has been a few years since I setup virtual hosts with my apache setup. I actually forgot how to set it up again, Oh well.

If I remember correctly I enable this module in the httpd file:
Code:
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
Then I got into the "extra" folder, open up the "httpd-vhosts" file. This is where I get a little blurry. I don't remember exactly how to setup the file. If I was to setup a //www.heeter1.com// & //www.heeter2.com//, I would do this:

Code:
NameVirtualHost *:80  # listen on all interfaces (loopback and nic1) on  port 80

<VirtualHost *:80>
   ServerName localhost
    DocumentRoot C:/apache/htdocs/  
</VirtualHost>

<VirtualHost  *:80>
   ServerName heeter1
   ServerAlias www.heeter1.com
   DocumentRoot C:/apache/htdocs/heeter1
   <Directory  "C:/apache/htdocs/heeter1">
      Options Indexes FollowSymLinks
       AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>  
</VirtualHost>

<VirtualHost  *:80>
    ServerName heeter2
    ServerAlias www.heeter2.com
    DocumentRoot C:/apache/htdocs/heeter2
    <Directory  "C:/apache/htdocs/heeter2">
      Options Indexes FollowSymLinks
       AllowOverride All
      Order allow,deny
      Allow from all
     </Directory>  
</VirtualHost>

Also, I don't remember if I have to mod the httpd file any other way.

Any assistance would be greatly appreciated.

Thanks

Heeter
 
that looks good so far... in the httpd file, under #virtual hosts you will need to

Include conf/extra/http_vhosts.conf

and depending on what version you're using, you 'might' also have to use
LoadModule alias_module modules/mod_alias.so

otherwise my thoughts are...

I wouldn't bother keeping the default localhost apache/htdocs in there unless you're using it for a reason...

don't know if this is better or not, but if your options aren't going to change on any of your virtual hosts, you can put the <directory> options directives in the main conf file and it will apply to them all (you can still specify per-host as needed)... (thoughts on this one anyone else? security issues? anything?)

it's probably not a bad idea to use directories outside of your apache install directory, even a seperate partition or physical drive...

What are they actually resolving to? you're an actual nameserver or something you will need something in there to point each name to your computer and each host besides your domain name... meaning you'll need dyndns or something to resolve the request for each host...
lets say you got free dyndns and registered heeter1.free.dns & heeter2.free.dns, the way I would set it up would look something like this...

#name based virtual hosting
NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.heeter1.com
ServerAlias heeter1.free.dns
DocumentRoot C:/heeternet/heeter1/

CustomLog C:/heeternet/heeter1/logs/heeter1.access.log
combined
ErrorLog C:/heeternet/heeter1/logs/heeter1.error.log

</VirtualHost>

#

<VirtualHost *:80>
ServerName www.heeter2.com
ServerAlias heeter2.free.dns
DocumentRoot C:/heeternet/heeter2/

CustomLog C:/heeternet/heeter2/logs/heeter2.access.log
combined
ErrorLog C:/heeternet/heeter2/logs/heeter2.error.log

</VirtualHost>


hope this helps...
 
Attached are templates I use myself and a script I knocked up to save me some work.

This is for Apache 2.2 running PHP 5.2.13 as FastCGI on FreeBSD and zsh instead of bash, you'll need to tweak for your usage. Script should work in bash to since zsh is a bourne shell.
 

Attachments

  • apache_vhost_maker.txt
    653 bytes · Views: 238
  • vhost_template.txt
    773 bytes · Views: 242
Thanks ApparitionX,

That really helped.

Hi LofLA, That is a little outside of what I am looking for, but it is very helpful to see someone else's setup, to give me ideas.............

Heeter
 
You're very welcome heeter. :)
btw, take another look at LofLA's template, you may want to use the ServerAdmin email... directive he has in the 1st line (i keep a common default in my main conf file so i leave it out by habit)

LofLA... nice man, I like the host maker, might have to implement that if you don't mind... thanks :)

now if only i could figure out my rewrite issues lol
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back