Vhost_alias & more

This is a discussion on Vhost_alias & more within the Linux Web Servers forums, part of the Web Server and Related Forums category; Hi, I'm trying to set up on an apache 2.0 server the following configuration: http://mydomain.net => /...


Go Back   Usenet Forums > Web Server and Related Forums > Linux Web Servers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-08-2006
Matthieu
 
Posts: n/a
Default Vhost_alias & more

Hi,

I'm trying to set up on an apache 2.0 server the following configuration:

http://mydomain.net => /home/mydomain.net/_
http://www.mydomain.net => /home/mydomain.net/www
http://sub1.mydomain.net => /home/mydomain.net/sub1
http://sub2.mydomain.net => /home/mydomain.net/sub2
http://*.mydomain.net => /home/mydomain.net/_

I can do that with several <VirtualHost> with different ServerName, but
I don't want annoyed me by adding a new directive for each subdomain.

I've tried the VirtualDocumentRoot in that way:
VirtualDocumentRoot /home/mydomain.net/%-3+
and it works pretty good for existing subdomain, but I've got an 404
error for other domain.
So how can I keep this setting but redirecting unexisting subdomain (no
folder in /home/mydomain.net/) to a default one ?

Regards,

Matthieu
  #2 (permalink)  
Old 01-17-2006
Jorey Bump
 
Posts: n/a
Default Re: Vhost_alias & more

Matthieu <news@plouk.net> wrote in news:43c0f55a$0$21206
$626a54ce@news.free.fr:

> Hi,
>
> I'm trying to set up on an apache 2.0 server the following

configuration:
>
> http://mydomain.net => /home/mydomain.net/_
> http://www.mydomain.net => /home/mydomain.net/www
> http://sub1.mydomain.net => /home/mydomain.net/sub1
> http://sub2.mydomain.net => /home/mydomain.net/sub2
> http://*.mydomain.net => /home/mydomain.net/_
>
> I can do that with several <VirtualHost> with different ServerName, but
> I don't want annoyed me by adding a new directive for each subdomain.
>
> I've tried the VirtualDocumentRoot in that way:
> VirtualDocumentRoot /home/mydomain.net/%-3+
> and it works pretty good for existing subdomain, but I've got an 404
> error for other domain.
> So how can I keep this setting but redirecting unexisting subdomain (no
> folder in /home/mydomain.net/) to a default one ?


I personally wouldn't clutter up the home directory with resources
devoted to virtual hosts. It makes more sense to logically separate them
in a single directory:

/var/www/hosts/example.com
/var/www/hosts/www.example.com
/var/www/hosts/support.example.com

Then, to use simplified mass virtual hosting, you could put this in a
single VirtualHost directive:

VirtualDocumentRoot /var/www/hosts/%0/site

This will match the host in the request, and automatically serve its
pages. For example:

http://www.example.com/index.html

would represent this file:

/var/www/hosts/www.example.com/site/index.html

If you want to use the same files for different hosts, just create
symlinks:

ln -s /var/www/hosts/www.example.com /var/www/hosts/example.com

As for directing hosts that have no configuration in apache (but resolve
to the same IP) to a default set of pages, you might be able to specify a
default IP-based virtual host before your name-based ones:

NameVirtualHost *

<VirtualHost 192.168.1.2>
ServerName example.com
DocumentRoot /var/www/hosts/example.com/site
</VirtualHost>

<VirtualHost *>
VirtualDocumentRoot /var/www/hosts/%0/site
UseCanonicalName Off
</VirtualHost>

There are pros and cons to this scenario. Mass virtual hosting is
convenient because configuration only requires a DNS record to be added.
Use of a default host to catch all other requests to the IP can be handy
when dealing with probes, but I probably wouldn't use it for anything
important. Finally, pointing multiple names to the same set of pages can
dilute your search engine rankings. YMMV.




 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:47 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0