Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO do multiple virtual hosts on apache2
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
karneevor
n00b
n00b


Joined: 10 Dec 2003
Posts: 47
Location: Denmark

PostPosted: Tue Apr 05, 2005 3:40 pm    Post subject: HOWTO do multiple virtual hosts on apache2 Reply with quote

HOWTO do multiple virtual hosts on apache2

I'm writing this because I could find it in the first place.

This is my first howto, so bear with me. :-) If some of you could suggest some BB tags to make it look more readable, please tell me.

My setup
I need to have 3 virtual servers running. I created 3 new directories in /var/www/localhost and put my php files in those directories.

Installing apache2
First we install apache:
Code:
emerge apache


Emerge php and mysql if you need. I certainly did. Remember to enable php in /etc/conf.d/apache2 if you need it.

Add apache to the default runlevel:
Code:
rc-update add apache2 default


Configuring apache
When I start apache, it complains about "fully quallified server name" or the likes of it. Go into /etc/apache2/conf/apache2.conf and set the right ServerName.

Go to the section Virtual Hosts and uncomment:
Code:
Include conf/vhosts/vhosts.conf


Save and exit.

Edit the /etc/apache2/conf/vhosts/vhosts.conf

Insert the following in the end of the file(the rest is commented allready):
Code:
NameVirtualHost *:80

<VirtualHost *:80>
  ServerName www.provingground.dk
  ServerAlias provingground.dk *.provingground.dk
  ServerAdmin webmaster@provingground.dk
  DocumentRoot /var/www/localhost/provingground.dk
  ServerPath /www.provingground.dk
  <Directory /var/www/localhost/provingground.dk>
    Order Allow,Deny
    Allow from all
  </Directory>
  Setenv VLOG /var/log/apache2/
  ErrorLog /var/log/apache2/provingground_dk_error_log
  CustomLog /var/log/apache2/provingground_dk_access_log combined
</VirtualHost>

<VirtualHost *:80>
  ServerName   www.charlottearp.dk
  ServerAlias  charlottearp.dk *.charlottearp.dk
  ServerAdmin  webmaster@charlottearp.dk
  DocumentRoot /var/www/localhost/charlottearp.dk
  ServerPath   /www.charlottearp.dk
  <Directory /var/www/localhost/charlottearp.dk>
    Order Allow,Deny
    Allow from all
  </Directory>
  Setenv VLOG /var/log/apache2/
  ErrorLog /var/log/apache2/charlottearp_dk_error_log
  CustomLog /var/log/apache2/charlottearp_dk_access_log combined
</VirtualHost>

<VirtualHost *:80>
  ServerName www.it-crew.dk
  ServerAlias it-crew.dk *.it-crew.dk
  ServerAdmin webmaster@it-crew.dk
  DocumentRoot /var/www/localhost/it-crew.dk
  ServerPath /www.it-crew.dk
  <Directory /var/www/localhost/it-crew.dk>
    Order Allow,Deny
    Allow from all
  </Directory>
  Setenv VLOG /var/log/apache2/
  ErrorLog /var/log/apache2/it-crew_dk_error_log
  CustomLog /var/log/apache2/it-crew_dk_access_log combined

</VirtualHost>


Some explanation about the configuration:
    The <Directory> directive is nesesary to get it working. I spent hours to find the solution. I got an 403 error from the web-server.

    It's a good idea to have each virtual host writing to its own set of log files.


Start apache
It's time to test apache. Run:
Code:
/etc/init.d/apache2 start


Make absolutely sure that DNS is set up correct or the domainname is set in your /etc/hosts.

Good luck.
_________________
Kind regards.

Karneevor
Denmark

"I'm really not interested in public opinion polls on my tactical decisions" - Admiral Tolwyn
Back to top
View user's profile Send private message
christsong84
Veteran
Veteran


Joined: 06 Apr 2003
Posts: 1003
Location: GMT-8 (Spokane)

PostPosted: Tue Apr 05, 2005 4:16 pm    Post subject: Reply with quote

methinks this belongs in the documentation, tips & tricks forum ;)

but great howto :)
_________________
while(true) {self.input(sugar);} :twisted:
Back to top
View user's profile Send private message
amiatrome
Apprentice
Apprentice


Joined: 28 Jun 2004
Posts: 180
Location: Campus | Arena Country Club | Home

PostPosted: Tue Apr 05, 2005 4:44 pm    Post subject: Reply with quote

Haven't tried it yet but it looks good. :wink:
_________________
blog | homepage | alias | prompts
Back to top
View user's profile Send private message
perseguidor
Apprentice
Apprentice


Joined: 01 Aug 2004
Posts: 278
Location: West Kingdom of Buenos Aires

PostPosted: Tue Apr 05, 2005 8:18 pm    Post subject: Reply with quote

It's a nice HOWTO, I'm sure people will find it handy.

Personally, I prefer the dynamic hosts way. I give my friends subdomains, so they sure come handy for me, as all I have to do is create a new directory inside /var/www and it's already set.

To go that way, you just have to uncomment

Code:
Include conf/vhosts/dynamic-vhosts.conf


in apache2.conf instead. Then check in vhosts/dynamic-vhosts.conf that

Code:
VirtualDocumentRoot /var/www/%0/
is set.

Finally, create directories of the form /var/www/subdomain.domain.com and you're good to go. Oh, don't forget to set your DNS to redirect *.yourdomain.com to your machine instead of doing so only for explicit domains.

I hope this little contribution helped someone :)
_________________
O make me a mask!
Back to top
View user's profile Send private message
perseguidor
Apprentice
Apprentice


Joined: 01 Aug 2004
Posts: 278
Location: West Kingdom of Buenos Aires

PostPosted: Tue Apr 05, 2005 8:21 pm    Post subject: Reply with quote

This has been covered before:

http://gentoo-wiki.com/Virtual_domain_hosting

But it's nice to have yours here, I'd say.
_________________
O make me a mask!
Back to top
View user's profile Send private message
harshaw
n00b
n00b


Joined: 01 Sep 2003
Posts: 3

PostPosted: Wed Apr 27, 2005 3:19 am    Post subject: Reply with quote

Note that if you are missing:

NameVirtualHost *:80

only the first site will work :/
Back to top
View user's profile Send private message
rernst
n00b
n00b


Joined: 12 Mar 2004
Posts: 14

PostPosted: Tue May 31, 2005 8:10 pm    Post subject: Reply with quote

The last comment should be BOLDED as big as it gets. I chased it for days on end.
Back to top
View user's profile Send private message
slay
n00b
n00b


Joined: 07 Feb 2006
Posts: 5
Location: Latvia

PostPosted: Tue Jan 23, 2007 7:00 pm    Post subject: Reply with quote

There is no need to test this method. I can see with naked eye that this is a realy good , plain and SIMPLE howto. Greajob. This should be in tips&tricks
_________________
God among the living
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum