View previous topic :: View next topic |
Author |
Message |
karneevor n00b


Joined: 10 Dec 2003 Posts: 47 Location: Denmark
|
Posted: Tue Apr 05, 2005 3:40 pm Post subject: HOWTO do multiple virtual hosts on apache2 |
|
|
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:
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 |
|
 |
christsong84 Veteran


Joined: 06 Apr 2003 Posts: 1003 Location: GMT-8 (Spokane)
|
Posted: Tue Apr 05, 2005 4:16 pm Post subject: |
|
|
methinks this belongs in the documentation, tips & tricks forum
but great howto  _________________ while(true) {self.input(sugar);}  |
|
Back to top |
|
 |
amiatrome Apprentice


Joined: 28 Jun 2004 Posts: 180 Location: Campus | Arena Country Club | Home
|
Posted: Tue Apr 05, 2005 4:44 pm Post subject: |
|
|
Haven't tried it yet but it looks good.  _________________ blog | homepage | alias | prompts |
|
Back to top |
|
 |
perseguidor Apprentice


Joined: 01 Aug 2004 Posts: 278 Location: West Kingdom of Buenos Aires
|
Posted: Tue Apr 05, 2005 8:18 pm Post subject: |
|
|
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 |
|
 |
perseguidor Apprentice


Joined: 01 Aug 2004 Posts: 278 Location: West Kingdom of Buenos Aires
|
|
Back to top |
|
 |
harshaw n00b

Joined: 01 Sep 2003 Posts: 3
|
Posted: Wed Apr 27, 2005 3:19 am Post subject: |
|
|
Note that if you are missing:
NameVirtualHost *:80
only the first site will work :/ |
|
Back to top |
|
 |
rernst n00b

Joined: 12 Mar 2004 Posts: 14
|
Posted: Tue May 31, 2005 8:10 pm Post subject: |
|
|
The last comment should be BOLDED as big as it gets. I chased it for days on end. |
|
Back to top |
|
 |
slay n00b

Joined: 07 Feb 2006 Posts: 5 Location: Latvia
|
Posted: Tue Jan 23, 2007 7:00 pm Post subject: |
|
|
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 |
|
 |
|