You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Veatch, David W" <Da...@eScout.com> on 2001/02/07 17:55:02 UTC

Perl Sections, NameVirtualHost, and Aliases

Yo,

Has anyone successfully built a fully perl conf file with multiple virtual
hosts on the same IP?  I'm giving it my best, but just can't quite get it to
work.  I'm stuck on aliases.  The Eagle book and the mod_perl guide have
both been of great help getting this far, but I can't find an example of
setting anything where "Directive is Repeated Multiple Times" (which may be
an indication that it just don't work).  I just started on this project, and
this is the first major roadblock.  Here are the relevant portions (I hope)
of the config for reference.  Thank you in advance for any and all
help/clues.  This is getting deeper than I've previously gotten, so I'm
learning as I go.  An RTFM is welcome, just tell me which M and where. :)

<Perl>
#!/usr/local/bin/perl
# Trimmed for brevity here... the real file is MUCH larger

$Apache::Server::StrictPerlSections = 1;
$Apache::Server::SaveConfig = 1;

$ServerName = `hostname`;
$ServerType = 'standalone';
$ServerRoot = '/www';

my $conf_root = $ServerRoot . '/conf';
my $logs_root = $ServerRoot . '/logs';    
my $vhosts_root = $ServerRoot . '/vhosts';

# olorin eq prod, erasmus eq dev
if ($ServerName =~ /olorin/) { 
	$NameVirtualHost = '192.168.0.3'; 
}
elsif ($ServerName =~ /erasmus/) { 
	$NameVirtualHost = '192.168.0.2'; 
}

my $NameVirtualHostIP = $NameVirtualHost . ':80';

$KeepAlive = 'Off';
$ExtendedStatus = 'On';
$UseCanonicalName = 'Off';
$HostnameLookups = 'Off';
$LogLevel = 'warn';

$VirtualHost{$NameVirtualHostIP} = [
# WWW.ACQUISITIONS.ORG
{
	ServerName => 'www.acquisitions.org',
	ServerAlias => 'acquisitions.org',
	DocumentRoot => "$vhosts_root/www.acquisitions.org/htdocs",
	ScriptAlias => [
		'/cgi-bin/' => "$vhosts_root/www.acquisitions.org/cgi-bin/" 
	],
	CustomLog => "$logs_root/www.acquisitions.org_access_log combined",
	ErrorLog => "$logs_root/www.acquisitions.org_error_log",
},
# MEMBERS.RECKONING.ORG
{
	ServerName => 'members.reckoning.org',
	Alias => {
		[ '/images' => "$vhosts_root/members.reckoning.org/images"
],
		[ '/css' => "$vhosts_root/members.reckoning.org/css" ],
	},
	ErrorLog => "$logs_root/members.reckoning.org_error_log",
	TransferLog => "$logs_root/members.reckoning.org_access_log",

	PerlAuthenHandler => 'Apache::AuthDBI::authen',
	PerlSetVar => {
		Auth_DBI_data_source => 'dbi:Pg:dbname=reckdb',
		Auth_DBI_username => 'dvicci',
		Auth_DBI_pwd_table => 'user_profile',
		Auth_DBI_uid_field => 'user_username',
		Auth_DBI_pwd_field  => 'user_password',
		Auth_DBI_pwd_whereclause => '"user_usertype>0"',
		Auth_DBI_encrypted => 'off',
	},
	Location => {
		'/' => {
			SetHandler => 'perl-script',
			PerlInitHandler => 'Apache::StatINC',
			PerlHandler => 'Reckoning::IndexHandler::members',
	
			AuthName => 'theReckoning',
			AuthType => 'Basic',
			Limit => {
				'GET POST' => {
					require => 'valid-user',
				},
			},
		},
		'/images' => {
			SetHandler => 'default-handler',
		},
		'/css' => {
			SetHandler => 'default-handler',
		},
		'/Error' => {
			SetHandler => 'perl-script',
			PerlHandler => 'Reckoning::Error',
		},
		'/LoginError' => {
			SetHandler => 'perl-script',
			PerlHandler => 'Reckoning::LoginError',
		},
	},
	ErrorDocument => {
		'401' => '/LoginError',
	}
},
# WWW.RECKONING.ORG
{
	ServerName => 'www.reckoning.org',
	ServerAlias => 'reckoning.org',
	Alias => {
		[ '/images' => "$vhosts_root/members.reckoning.org/images"
],
		[ '/css' => "$vhosts_root/members.reckoning.org/css" ],
	},
	ErrorLog => "$logs_root/www.reckoning.org_error_log",
	TransferLog => "$logs_root/www.reckoning.org_access_log",
	Location => {
		'/' => {
			SetHandler => 'perl-script',
			PerlInitHandler => 'Apache::StatINC',
			PerlHandler => 'Reckoning::IndexHandler::www',
		},
		'/images' => {
			SetHandler => 'default-handler',
		},
		'/css' => {
			SetHandler => 'default-handler',
		},
		'/Error' => {
			SetHandler => 'perl-script',
			PerlHandler => 'Reckoning::Error',
		},
		'/LoginError' => {
			SetHandler => 'perl-script',
			PerlHandler => 'Reckoning::LoginError',
		}
	},
	ErrorDocument => {
		'401' => '/LoginError',
	}
}
];

__END__
</Perl>

Re: Perl Sections, NameVirtualHost, and Aliases

Posted by Wade Burgett <wa...@burgettsys.com>.
    This is working for me.  I do some aliasing of mod_perl directories outside
of the <perl> section for stuff that all my hosts need to share so my httpd.conf
is not all perl, but I do have some aliasing going on.

    There's some stuff there to pull my records out of a database but basically
the $Company hash_ref is for each company I host.


<Perl>
use Asql::utility;
use Apache::PerlSections();
my $statement = "select ID,Company,webhost,rootdir,master_user,domain,rt from
Companies where webhost is not  NULL and master_user is not NULL";
my $dbh = connect_system_db();
my $sth = $dbh->prepare($statement)|| die "$DBI::errstr\n";
$sth->execute()|| die "$DBI::errstr\n";
my $counter = 0;

while ($Company = $sth->fetchrow_hashref()){

        $$Company{ServerAdmin} = "$$Company{master_user}\@"."$$Company{domain}";
        my $statement = "select Domain from domains where CompanyID=?";
        my $sth2 = $dbh->prepare($statement)|| die "$DBI::errstr\n";
        $sth2->execute($$Company{ID})|| die "$DBI::errstr\n";
        my $othersites = $sth2->fetchall_arrayref;
        @$othersites = map {$_="www.$_";} @$othersites;
        #build the hosts

                $VirtualHost{'192.168.0.50:80'}[$counter] = {
                     SSLDisable   => '',
                     ServerName   => "$$Company{webhost}",
                     DocumentRoot => "$$Company{rootdir}/public_html",
                     ErrorLog     => "$$Company{rootdir}/log/error.log",
                     CustomLog  => "$$Company{rootdir}/log/access.log combined",
                     ServerAdmin  => "$$Company{ServerAdmin}",
                     CheckSpelling => 'on',
                     "ErrorDocument 404" => "/errors/404.shtml",
                     Alias => ["/webrt" => "/var/burgettsys/rt/lib/images"],
                     ScriptAlias => ["/rt" => "$$Company{rootdir}/rt/bin/cgi/"],
                     ServerAlias => $othersites,
                };
        $counter++;
};

#print STDERR Apache::PerlSections->dump();
__END__

</Perl>



Dave Baker wrote:

> > Has anyone successfully built a fully perl conf file with multiple virtual
> > hosts on the same IP?  I'm giving it my best, but just can't quite get it to
> > work.  I'm stuck on aliases.  The Eagle book and the mod_perl guide have
> > both been of great help getting this far, but I can't find an example of
> > setting anything where "Directive is Repeated Multiple Times" (which may be
> > an indication that it just don't work).
>
> Not a direct answer, but an alternative to fighting with the data
> structure is just just plug a programmatic $PerlConfig .= $string and
> build the VirtualHosts as if they were plain text.
>
> Not as elegant as doing this the hard way, but it's also easier to
> explain if you have to hand the config file off to someone who knows
> Apache but not Perl.
>
> Dave
>
> --
>
> -  Dave Baker  :  dave@dsb3.com  :  dave@devbrain.com  :  http://dsb3.com/
> GnuPG: 1024D/D7BCA55D / 09CD D148 57DE 711E 6708  B772 0DD4 51D5 D7BC A55D
>
>   ------------------------------------------------------------------------
>    Part 1.2Type: application/pgp-signature

--
Wade Burgett
Burgett Systems
http://www.burgettsys.com/
wadeb@burgettsys.com




Re: Perl Sections, NameVirtualHost, and Aliases

Posted by Dave Baker <da...@dsb3.com>.
> Has anyone successfully built a fully perl conf file with multiple virtual
> hosts on the same IP?  I'm giving it my best, but just can't quite get it to
> work.  I'm stuck on aliases.  The Eagle book and the mod_perl guide have
> both been of great help getting this far, but I can't find an example of
> setting anything where "Directive is Repeated Multiple Times" (which may be
> an indication that it just don't work).

Not a direct answer, but an alternative to fighting with the data
structure is just just plug a programmatic $PerlConfig .= $string and
build the VirtualHosts as if they were plain text.

Not as elegant as doing this the hard way, but it's also easier to
explain if you have to hand the config file off to someone who knows
Apache but not Perl.


Dave 

-- 

-  Dave Baker  :  dave@dsb3.com  :  dave@devbrain.com  :  http://dsb3.com/
GnuPG: 1024D/D7BCA55D / 09CD D148 57DE 711E 6708  B772 0DD4 51D5 D7BC A55D


Re: Perl Sections, NameVirtualHost, and Aliases

Posted by Jason Terry <jt...@cartmanager.net>.
I use this code to pull my domains from a VERY simple mySQL db


----- Original Message ----- 
From: "G.W. Haywood" <ge...@www.jubileegroup.co.uk>
To: "Veatch, David W" <Da...@eScout.com>
Cc: <mo...@apache.org>
Sent: Wednesday, February 07, 2001 10:04 AM
Subject: Re: Perl Sections, NameVirtualHost, and Aliases


> Hi there,
> 
> On Wed, 7 Feb 2001, Veatch, David W wrote:
> 
> > Has anyone successfully built a fully perl conf file with multiple virtual
> > hosts on the same IP?
> 
> Dunno if it will work for you in those circumstances, but have you
> looked at mod_macro?  I used it last year and it was fine for an
> ordinary (although complex, multiple virtual hosts) http.conf.
> 
> 73,
> Ged.

Re: Perl Sections, NameVirtualHost, and Aliases

Posted by "G.W. Haywood" <ge...@www.jubileegroup.co.uk>.
Hi there,

On Wed, 7 Feb 2001, Veatch, David W wrote:

> Has anyone successfully built a fully perl conf file with multiple virtual
> hosts on the same IP?

Dunno if it will work for you in those circumstances, but have you
looked at mod_macro?  I used it last year and it was fine for an
ordinary (although complex, multiple virtual hosts) http.conf.

73,
Ged.


Re: Reading email with mod_perl

Posted by Glorfindel <le...@akio-solutions.com>.
Hi

Check MIME::Parser ( recent version to avoid error with bad use of date.pm instead of Date.pm )

Jason Terry wrote:

> Does anybody have an information on how to read a MIME encoded email attachment with mod_perl?

--
Don't be irreplaceable, if you can't be replaced, you can't be promoted.




Re: Reading email with mod_perl

Posted by Patrick <pa...@patoche.org>.
On Wed, Feb 07, 2001 at 11:29:59AM -0700, Jason Terry took time to write:
> Does anybody have an information on how to read a MIME encoded email attachment with mod_perl?

This is not specific to modperl.
The module MIME::Entity does that very nicely IMNSHO.

-- 
Patrick.
``C'est un monde qui n'a pas les moyens de ne plus avoir mal.''

Re: Reading email with mod_perl

Posted by Victor Michael Blancas <vb...@yahoo.com>.
use the module MIME-tools.

On Wed, 7 Feb 2001, Jason Terry wrote:

> Does anybody have an information on how to read a MIME encoded email attachment with mod_perl?
>

-- 
Mike


Re: Reading email with mod_perl

Posted by Matt Sergeant <ma...@sergeant.org>.
On Wed, 7 Feb 2001, Jason Terry wrote:

> Does anybody have an information on how to read a MIME encoded email
> attachment with mod_perl?

Depends where you're reading it from, but there are lots of modules on
CPAN that can do this. Do a search for POP, IMAP, or MIME on
search.cpan.org.

-- 
<Matt/>

    /||    ** Founder and CTO  **  **   http://axkit.com/     **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // ** mod_perl news and resources: http://take23.org  **
     \\//
     //\\
    //  \\


Reading email with mod_perl

Posted by Jason Terry <jt...@cartmanager.net>.
Does anybody have an information on how to read a MIME encoded email attachment with mod_perl?


Re: Perl Sections, NameVirtualHost, and Aliases

Posted by Benjamin Trott <be...@rhumba.pair.com>.
I think that this:

> PerlSetVar => {
> Auth_DBI_data_source => 'dbi:Pg:dbname=reckdb',
> Auth_DBI_username => 'dvicci',
> Auth_DBI_pwd_table => 'user_profile',
> Auth_DBI_uid_field => 'user_username',
> Auth_DBI_pwd_field  => 'user_password',
> Auth_DBI_pwd_whereclause => '"user_usertype>0"',
> Auth_DBI_encrypted => 'off',
> },

should look more like this:

    PerlSetVar => [
        [ Auth_DBI_data_source => 'dbi:Pg:dbname=reckdb' ],
        [ Auth_DBI_username => 'dvicci' ],
        [ Auth_DBI_pwd_table => 'user_profile' ],
        [ Auth_DBI_uid_field => 'user_username' ],
        [ Auth_DBI_pwd_field  => 'user_password' ],
        [ Auth_DBI_pwd_whereclause => '"user_usertype>0"' ],
        [ Auth_DBI_encrypted => 'off' ],
    ],

That's the format I use when using PerlSetVar.

bye,
Ben