Re: Apache 1.3 mass virtual hosting recipe

2004-09-22 Thread Johann Botha
Hi Fraser @2004.09.22_03:13:17_GMT+0200

 I finally got around to trying out mod_rewrite and it looks like things will 
 work exactly as I'd hoped.

 Obviously under this scheme all hostnames get treated the same, you would have 
 to override the defaults in some cases (SSL sites for example) but that can 
 be done by adding normal rules in virtualhost or Directory containers.

I remember having a similar config when I last tried this, but..

running a script from mod_rewrite was not reliable, sometimes it just did
not work... restart apache and it worked again. maybe it was just the
version I used.

my big problem was..

1) I wanted the script to read the path from LDAP
   which I did have working.

2) I wanted to enable / disable things like PHPengine for the virtual
   host based on LDAP settings.

How do I do 2 ?   

-- 
 We are all worms.  But I do believe I am a glowworm.
 -- Winston Churchill

 frogfoot networks   +27.21.689.3867   blue.frogfoot.net
 www.frogfoot.com ..frogs are ferocious carnivores by nature


signature.asc
Description: Digital signature


Re: Apache 1.3 mass virtual hosting recipe

2004-09-22 Thread Fraser Campbell
On September 22, 2004 03:04 am, Johann Botha wrote:

 running a script from mod_rewrite was not reliable, sometimes it just did
 not work... restart apache and it worked again. maybe it was just the
 version I used.

Hmm, I don't like the sounds of that.  Hopefully it was just the version you 
used.  Or a problem with the script talking to LDAP, since my script (at 
least for now) is self-contained I hope I don't run into issues.  If my 
solution proves problematic I will report back.

 2) I wanted to enable / disable things like PHPengine for the virtual
    host based on LDAP settings.

You could do it in the script, if file extension is .php then rewrite the 
request to a cannot execute message.  Alternatively (what I had planned to 
do) is just disable the engine in directories where I don't want it (that 
would be using config files), something like this is supposed to work:

Directory /var/www/net/wehave
php_admin_flag engine off
/Directory

-- 
Fraser Campbell [EMAIL PROTECTED] http://www.wehave.net/
Georgetown, Ontario, Canada   Debian GNU/Linux



Re: Apache 1.3 mass virtual hosting recipe

2004-09-22 Thread Johann Botha
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Fraser @2004.09.22_13:12:19_GMT+0200

  2) I wanted to enable / disable things like PHPengine for the virtual
  ? ?host based on LDAP settings.
 
 You could do it in the script, if file extension is .php then rewrite the 
 request to a cannot execute message.  Alternatively (what I had planned to 
 do) is just disable the engine in directories where I don't want it (that 
 would be using config files), something like this is supposed to work:
 
 Directory /var/www/net/wehave
 php_admin_flag engine off
 /Directory

hmm.. thats where I stopped investigating this option,
I dont want to be editing config files.

this looks interesting..
http://andreasbrenk.com/opensource/modcfgldap/

anybody using it?

- -- 
 We are all worms.  But I do believe I am a glowworm.
 -- Winston Churchill

 frogfoot networks   +27.21.689.3867   blue.frogfoot.net
 www.frogfoot.com ..frogs are ferocious carnivores by nature
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Debian :: The Universal Operating System

iD8DBQFBUWWkSlwwQibN9dQRAvAxAJ9df8TsyCElFOtG1wGyTq3bde7vGwCcCoHP
1hOBUUYhAJrX/cgzb/XJbmM=
=l0LV
-END PGP SIGNATURE-


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Apache 1.3 mass virtual hosting recipe

2004-09-22 Thread Raúl Alexis Betancort Santana
El Miércoles 22 Septiembre 2004 12:12, Fraser Campbell escribió:
 On September 22, 2004 03:04 am, Johann Botha wrote:
  running a script from mod_rewrite was not reliable, sometimes it just did
  not work... restart apache and it worked again. maybe it was just the
  version I used.

 Hmm, I don't like the sounds of that.  Hopefully it was just the version
 you used.  Or a problem with the script talking to LDAP, since my script
 (at least for now) is self-contained I hope I don't run into issues.  If my
 solution proves problematic I will report back.

  2) I wanted to enable / disable things like PHPengine for the virtual
     host based on LDAP settings.

 You could do it in the script, if file extension is .php then rewrite the
 request to a cannot execute message.  Alternatively (what I had planned
 to do) is just disable the engine in directories where I don't want it
 (that would be using config files), something like this is supposed to
 work:

 Directory /var/www/net/wehave
 php_admin_flag engine off
 /Directory

I wonder how running a script inside a mod_rewrite rule is better that 
defining a new NameVirtualHost directive, moreover taking into account that 
that rewriting rule will run the script EVERY TIME a request reach the 
server, I hope you don't have high volume traffict to that server or you will 
go into troubles.

I better follow this way ...

httpd.conf (apache 1.3.X, apache 2.X doit automaticatly)
...
Include /etc/apache/domains.d
...

then simple create the domain.conf file from a template for example, and 
drop it inside /etc/apached/domains.d a simple /etc/init.d/apache reload and 
thats all, no need to check on every request to were should I get the files.



Re: Apache 1.3 mass virtual hosting recipe

2004-09-22 Thread Fraser Campbell
On September 22, 2004 10:10 am, Raúl Alexis Betancort Santana wrote:

 I wonder how running a script inside a mod_rewrite rule is better that
 defining a new NameVirtualHost directive, moreover taking into account that

It's better (IMO) because I do not have to configure apache.  My admin 
interface is greatly simplified because apache configuration does not need to 
be done. I create a user who has a homedir in the appropriate location (or at 
least who has access to the appropriate created location) and setup is 
complete.

 that rewriting rule will run the script EVERY TIME a request reach the
 server, I hope you don't have high volume traffict to that server or you
 will go into troubles.

The script runs continually, it is not started for every incoming request.  
Apache has a filehandle for the script's stdin and stdout, the overhead of 
running the script will be very minimal and the script will not introduce 
much delay.  Checking for a few directories is no different than many apache 
servers that check for .htaccess files all the way up to the root of the 
filesystem, it does so very quickly.

When server traffic gets too high I will simply add servers but I see no 
reason why this setup can't host hundreds of typical low-volume sites, I may 
be proved wrong of course ;-)

I would not use this for a very high traffic site, I wouldn't host a very high 
traffic site on a shared server period.

 I better follow this way ...

 httpd.conf (apache 1.3.X, apache 2.X doit automaticatly)
 ...
 Include /etc/apache/domains.d
 ...

 then simple create the domain.conf file from a template for example, and
 drop it inside /etc/apached/domains.d a simple /etc/init.d/apache reload
 and thats all, no need to check on every request to were should I get the
 files.

On previous servers I have used the template approach.  I don't like to 
creating hundreds of nearly identical configs, to me identical means 
redundant.

-- 
Fraser Campbell [EMAIL PROTECTED] http://www.wehave.net/
Georgetown, Ontario, Canada   Debian GNU/Linux



Re: Apache 1.3 mass virtual hosting recipe

2004-09-22 Thread Fraser Campbell
On September 22, 2004 07:44 am, Johann Botha wrote:

      Directory /var/www/net/wehave
          php_admin_flag engine off
      /Directory

 hmm.. thats where I stopped investigating this option,
 I dont want to be editing config files.

Neither do I but in my case I anticipate 95% of the hosts being identical, if 
I have to setup a few sites with specific configs I can live with it.

-- 
Fraser Campbell [EMAIL PROTECTED] http://www.wehave.net/
Georgetown, Ontario, Canada   Debian GNU/Linux



Re: Apache 1.3 mass virtual hosting recipe

2004-09-21 Thread Fraser Campbell
Hi,

I finally got around to trying out mod_rewrite and it looks like things will 
work exactly as I'd hoped.  I'm posting this recipe since I was unable to 
find a documented example of how to do it and I figured lots of people might 
be interested in doing it.  It does need some more testing but at this point 
I see no reason why it will not work.

The basic concept is to create a directory and have apache serve it 
automatically under the correct domain name (zero config apache). Let's say I 
want to have wehave.net and www.wehave.net hosted on my server.  I could 
create a VirtualHost with ServerName wehave.net and ServerAlias 
www.wehave.net or I could do this:

  RewriteEngine on
  RewriteLog /tmp/junk
  RewriteLogLevel 9
  RewriteMap  vhosts-map  prg:/usr/local/sbin/vhost-redirector.pl
  RewriteRule ^/(.*)$ ${vhosts-map:%{HTTP_HOST}}$1

My perl script looks like this:

  #!/usr/bin/perl -wT
  use strict;
  $| = 1;
  while () {
# FIXME, do we need to do syntax checking on hostname?
chomp;
my @path = split(/\./, $_);
while ( ! -d '/var/www/' . join('/', reverse(@path)) . '/web/' and @path){
  shift @path;
}
if (@path) {
  print '/var/www/' . join('/', reverse(@path)) . /web/\n;
} else {
  print /var/www/web/\n;
}
  }

The end result is that once dns points something at your server simply 
creating the appropriate directory heirarchy is enough to host a given 
website (and aliases).  Given the previous example (hosting wehave.net), I 
would create the directory /var/www/net/wehave/web and 
http://wehave.net/whatever would translate to the filesystem 
as /var/www/net/wehave/web/whatever ... requests for 
http://www.wehave.net/whatever would translate to the same file unless I 
wanted to serve something different for that in which case I would just need 
to create /var/www/net/wehave/www/web/whatever 

If I want www.wehave.ca to be the same as wehave.net then I just link ...
ln -s /var/www/net/wehave /var/www/ca/wehave

Any site pointed to your server which doesn't have an appropriate config would 
end up directed to the filesystem directory /var/www/web ... there could be a 
default page there stating Site not configured.

One thing I haven't shown in my example is that you would have to either not 
rewrite shared paths (such as /icons/, /squirrelmail/, etc.) or you would 
have to hardcode those paths into the perl script.

The perl code starts when apache starts and stays resident so the extra 
overhead is minimal (I am guessing) i.e. you are not firing up a perl process 
for every single request.

Obviously under this scheme all hostnames get treated the same, you would have 
to override the defaults in some cases (SSL sites for example) but that can 
be done by adding normal rules in virtualhost or Directory containers.

On September 5, 2004 09:06 pm, Fraser Campbell wrote:
 Hi,

 I'm setting up a new server and would like to use mod_vhost_alias, or other
 mass virtual hosting method, if possible.  mod_vhost_alias is very simple
 to setup and works as advertised:

 LoadModule vhost_alias_module /usr/lib/apache/1.3/mod_vhost_alias.so
 UseCanonicalName Off
 VirtualDocumentRoot /var/www/%0/web

 Unfortunately, it is as simple as it is simple to setup ;-)  My question is
 in regards to ServerAlias.  Normal clients host their website at
 http://www.abcd.com/ but they (and I) also like it when http://abcd.com/
 works as well.  Is there any way (besides filesystem link) to make
 vhost_alias find the right DocumentRoot?

 Ideally I'd like a directory structure like this:

 /var/www/com/abcd/web/
 /var/www/com/abcd/subdomain/web/

 When serving http://www.abcd.com/ apache wouldn't
 find /var/www/com/abcd/www/web/ so it would fallback
 to /var/www/com/abcd/web/, if that were missing it would fallback
 to /var/www/com/web/ and then to /var/www/web/

 Perhaps something like the above is possible using mod_rewrite???  I'll
 keep plugging away for a while but if anyone knows the answer I'm all for
 shortcuts.

 Second question.  Supposing that the above can work somehow I'd like to use
 one common logfile for all virtualhosts, with the virtualhost's name
 prepended to each log line.  This is easy of course.  The catch of course
 is that I'd like to have consistent names for hosts, i.e. I don't want to
 be splitting off logfiles for www.abcd.com and abcd.com when those are
 actually the same site.

 Basically, I'd like apache logging to be smart enough to realize that it is
 actually serving abcd.com although the hostname in the request was
 www.abcd.com.

 --
 Fraser Campbell [EMAIL PROTECTED] http://www.wehave.net/
 Georgetown, Ontario, Canada   Debian GNU/Linux


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]