VHost

VHost

am 15.08.2007 06:50:48 von Computer Guy

I have tried to set up virtual hosts before and have failed. I am
giving it another go and hoping you guys can help me. I currently own
1 domain. Lets just call it allyourbase.com (just for fun). So at
the bottom of my apache config file I have this.
I must point out that I really do not understand this so what I put
below may not make much sense.

NameVirtualHost *:80

ServerName allyourbase.com
ServerAlias .allyourbase.com
DocumentRoot "/var/www/ayb"


I kinda got that to work but I am not really sure why it worked. If I
wanted a subdomain where would I put that? Just below the other one?
I tried to do this. for lets say beta.allyourbase.com

ServerName beta.allyourbase.com
ServerAlias beta.allyourbase.com
DocumentRoot "/var/www/beta"


As you can probably tell I dont really understand virtual hosts. I
have tries Apache's website and docs and this is what I got from
them. Is the apache config file the right place for this? Also if
someone could put in their vhost config for me that would be great.
In the apache config there is an include for /etc/apache2/sites/
enabled I checked that directory in there there is a file called 000-
default which basically has
NameVirtualHost *

ServerAdmin ...
DocumentRoot /var/www
The a bunch of privlages. Am I suppoed to keep that file. I
commented out the include for it and that is the only reason my little
vhost thing kinda worked. How do i make all this work, thx for the
help :D - Aaron

Re: VHost

am 15.08.2007 07:39:42 von Steve

On Tue, 14 Aug 2007 21:50:48 -0700, Computer Guy wrote:

> I have tried to set up virtual hosts before and have failed. I am
> giving it another go and hoping you guys can help me. I currently own
> 1 domain. Lets just call it allyourbase.com (just for fun). So at
> the bottom of my apache config file I have this.
> I must point out that I really do not understand this so what I put
> below may not make much sense.
>
> NameVirtualHost *:80
NameVirtualHost :80

>

> ServerName allyourbase.com
> ServerAlias .allyourbase.com
> DocumentRoot "/var/www/ayb"
>


>
> I kinda got that to work but I am not really sure why it worked. If I
> wanted a subdomain where would I put that? Just below the other one?
> I tried to do this. for lets say beta.allyourbase.com
>

> ServerName beta.allyourbase.com
> ServerAlias beta.allyourbase.com
You don't need an alias unless there's more than one url pointing at it.
> DocumentRoot "/var/www/beta"
>

>
> As you can probably tell I dont really understand virtual hosts. I
> have tries Apache's website and docs and this is what I got from
> them. Is the apache config file the right place for this? Also if
> someone could put in their vhost config for me that would be great.
> In the apache config there is an include for /etc/apache2/sites/
> enabled I checked that directory in there there is a file called 000-
> default which basically has
> NameVirtualHost *
>
> ServerAdmin ...
> DocumentRoot /var/www
> The a bunch of privlages. Am I suppoed to keep that file. I
> commented out the include for it and that is the only reason my little
> vhost thing kinda worked. How do i make all this work, thx for the
> help :D - Aaron

If you make the changes I suggest: put the ip address in your
namevirtualhost, each virtualhost directive is named, and on port 80, then
you'll have a) got it working, but b) also have ensured that your dns is
functioning correctly.

I would also, as a minimum, define separate logs for each virtualhost:

ErrorLog logs/allyourbase.com-error.log
CustomLog logs/allyourbase.com-access.log combined



Steve.

Re: VHost

am 15.08.2007 10:53:20 von unknown

Post removed (X-No-Archive: yes)

Re: VHost

am 15.08.2007 11:09:43 von shimmyshack

On Aug 15, 5:50 am, Computer Guy wrote:
> I have tried to set up virtual hosts before and have failed. I am
> giving it another go and hoping you guys can help me. I currently own
> 1 domain. Lets just call it allyourbase.com (just for fun). So at
> the bottom of my apache config file I have this.
> I must point out that I really do not understand this so what I put
> below may not make much sense.
>
> NameVirtualHost *:80
>
> ServerName allyourbase.com
> ServerAlias .allyourbase.com
> DocumentRoot "/var/www/ayb"
>

>
> I kinda got that to work but I am not really sure why it worked. If I
> wanted a subdomain where would I put that? Just below the other one?
> I tried to do this. for lets say beta.allyourbase.com
>
> ServerName beta.allyourbase.com
> ServerAlias beta.allyourbase.com
> DocumentRoot "/var/www/beta"
>

>
> As you can probably tell I dont really understand virtual hosts. I
> have tries Apache's website and docs and this is what I got from
> them. Is the apache config file the right place for this? Also if
> someone could put in their vhost config for me that would be great.
> In the apache config there is an include for /etc/apache2/sites/
> enabled I checked that directory in there there is a file called 000-
> default which basically has
> NameVirtualHost *
>
> ServerAdmin ...
> DocumentRoot /var/www
> The a bunch of privlages. Am I suppoed to keep that file. I
> commented out the include for it and that is the only reason my little
> vhost thing kinda worked. How do i make all this work, thx for the
> help :D - Aaron

the * means all_ip_addresses, so apache should answer for any IP that
your DNS points to,
so say you have a DNS entry that points to your public ip, forwarding
port 80 to your local machine - it should work if apache is set to
Listen *
or if you have a hosts file that locally points the domain to your LAN
ip, it should work as well, so * is a good option.

You can specify the port as port 80 so if you want all ips at port 80
use *:80 - when you create SSL vshosts these will go in a different
file and be fixed at port 443 probably, I personally use *:80 because
my apache doesnt answer on any other port for http traffic, and it is
also bound to 2 different IPs, so I use *, but for security (if your
machine has a few IP addresses and you dont want apache to serve some
of them, consider Steves idea of tying it to just one by specifying
the IP

What you have is OK, you commented out apaches default vhost file, but
you can now put a vhost file in its place say called vhosts.conf and
change the include filename to vhosts.conf, then put all your
directives for vhosts in there, this is good practise because you
might end up with quite a few directives in there

You should know that if you point a domain at your apache server and
there is NO vhost section for that domain then the FIRST one will be
use by default.
so in this case a request for noneofyourbases.com would be served by
allyourbase.com
if this is not what you want then consider setting up a default
"catchall" vhost directive as the top most entry called say

DocumentRoot "/var/www/nothing"

where there might just be a single index page, saying host not found.

You should also not end your vhost sections with but
only with
There is an upper limit to the amount of separate log files, but its
pretty big so do what Steve says and keep them separate for
convenience.