httpd conf for multiple vhosts using mod_perl
Robert Rendler
rendler at iinet.com
Mon Mar 10 03:47:43 CST 2003
On Wed, 05 Mar 2003 11:33:26 +1100
Tim Hunt <tim.hunt at its.monash.edu.au> wrote:
> We use mod_perl and HTML::Mason for the site.
>
> So, the first question is, can we have independent environments for each
> vhost? (separate doc root, different config files, ...)
Sure, that's pretty easy to do. One way is:
NameVirtualHost *
<VirtualHost *>
DocumentRoot /var/www/site1
ServerName site1.domain.com
PerlRequire /var/www/site1/handler.pl
DefaultType text/html
<FilesMatch "(\.html|\.mc|^[^\.]+)$>
SetHandler perl-script
PerlHandler HTML::Mason::Site1
</FilesMatch>
</VirtualHost>
<VirtualHost *>
DocumentRoot /var/www/site2
ServerName site2.domain.com
PerlRequire /var/www/site2/handler.pl
DefaultType text/html
<FilesMatch "(\.html|\.mc|^[^\.]+)$>
SetHandler perl-script
PerlHandler HTML::Mason::Site1
</FilesMatch>
</VirtualHost>
And so on. Basic looking handler.pl:
#!/usr/bin/perl
package HTML::Mason::Site1;
# Bring in main Mason package.
use HTML::Mason;
use HTML::Mason::ApacheHandler;
use strict;
my $ah = HTML::Mason::ApacheHandler->new(
comp_root => '/var/www/site1',
data_dir => '/home/user/site1/mason',
);
chown (Apache->server->uid, Apache->server->gid, $ah->interp->files_written);
sub handler {
my ($r) = @_;
return -1 if $r->content_type && $r->content_type !~ m|^text/|io;
my $status = $ah->handle_request($r);
return $status;
}
1;
You may want to look at this also for more information about setting such a
thing up http://www.masonbook.com/book/chapter-7.mhtml#TOC-ANCHOR-1
More information about the Melbourne-pm
mailing list