Apache Virtual Hosts file setup.

Discussion in 'Web Design & Coding' started by Heeter, May 17, 2010.

  1. Heeter

    Heeter Overclocked Like A Mother

    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
     
  2. Heeter

    Heeter Overclocked Like A Mother

    Messages:
    2,732
    Anyone?


    Heeter
     
  3. ApparitionX

    ApparitionX Sick of it all.

    Messages:
    117
    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...
     
  4. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    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.
     

    Attached Files:

  5. Heeter

    Heeter Overclocked Like A Mother

    Messages:
    2,732
    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
     
  6. ApparitionX

    ApparitionX Sick of it all.

    Messages:
    117
    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