View Single Post

  #3 (permalink)  
Old 10-23-2007
trpost@gmail.com
 
Posts: n/a
Default Re: Apache domain best practice??

On Oct 22, 6:10 pm, shimmyshack <matt.fa...@gmail.com> wrote:
> trp...@gmail.com wrote:
> > I have an apache 2.0.54 webserver that I want to setup to handle 10
> > small domains. In the past I have setup each domain to listen on port
> > 80, but burned a virtual ip in doing so. If possible I want to move
> > away from assigning a virtual ip to each new domain. I tried setting
> > up each domain using the same ip, but a different port i.e. 80, 8080,
> > 8081, etc, however am having trouble with users then having to access
> > the URL with the port i.e.www.testabc.com:8081

>
> > What is the best way or best practice when setting up an apache
> > webserver to handle multiple domains,

>
> > Thanks!

>
> use a single IP!!
> this is virtualhosting
>
> set you apache to listen on port 80
>
> then HTTP/1.1 (what every modern user agent uses) sends a host header
>
> host:www.bbc.co.uk
>
> in the request, this is passed to apache which therefore knows what
> the browser is looking for, and you set rules in virtualhost stanzas
> that tell apache where each host is
>
> the first virtualhost stanza is always used when no other host header
> matches any other virtualhost block so it tends to make sense to have
> the first virtualhost a generic one
>
> see apache docs under virtualhosting
>
> <VirtualHost *>
> DocumentRoot /var/www/generic_not_found/public
> </VirtualHost>
>
> <VirtualHost *>
> DocumentRoot /var/www/example.com/public
> ServerNamewww.example.com
> ServerAlias example.com
> </VirtualHost>
>
> #etc...


Thanks for the quick response... Just to make sure I understand, would
this work for example:

<VirtualHost *>
DocumentRoot /var/www/generic_not_found/public
</VirtualHost>

<VirtualHost *>
DocumentRoot /var/www/example.com/public
ServerName www.example.com
ServerAlias example.com
</VirtualHost>

<VirtualHost *>
DocumentRoot /var/www/test.com/public
ServerName www.test.com
ServerAlias test.com
</VirtualHost>

<VirtualHost *>
DocumentRoot /var/www/project.com/public
ServerName www.project.com
ServerAlias project.com
</VirtualHost>

....

So in the above I am listening on port 80 and 1 ip address, but
handling 3 different domains based on the ServerName in the
VirtualHost definition. I guess I was thrown off a bit because what I
gathered in the docs was that I could use the same ip, but only for
subdomains, where here I actually have different domains.