You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by André Warnier <aw...@ice-sa.com> on 2012/01/17 10:31:48 UTC

serve items in "lib" or "PATH" fashion

Hi.

I run a series of mostly-identical websites under Apache2/mod_perl2 (and Template::Toolkit).
Most of the time, these websites use a common /js/*.js javascript snippets directory, a 
common /cgi-bin/*.pl directory and so on. This is done via Alias'es in each website's 
<VirtualHost> configuration file, pointing to a common location.

However, once in a while - tending over time to become "quite often" - one of these 
websites will need a modified version of for example one of these javascript snippets or 
cgi-bin scripts.  At the moment, I solve that by giving this website, then, its own 
/cgi-bin/ directory, copying *all* the standard cgi-bin scripts there, changing the 
/cgi-bin/ Alias to point to this own cgi-bin directory, and then modifying the one cgi-bin 
script that is special for that website.

But of course then I am stuck forever now with this separate cgi-bin directory to 
maintain, containing not only the one script which is different, but all the others too.

I would much prefer if I could give each of these <VirtualHost> sections a list of 
directories in which to look for a target document or script, much like the way in which 
the PATH or PERL5LIB variables are used.

E.g. I would be happy if I could write this in the Apache configuration :

ScriptAlias /cgi-bin/ /var/www/site1/cgi-bin/;/var/www/global/cgi-bin/

and have Apache look first in the local one, then in the global one each time it is 
looking for a given script.  And similarly for other documents like javascript libraries.

Now my question is : does anyone know of an Apache add-on module doing something similar ? 
; does anyone know of an add-on mod_perl module which would do something of the kind ?

I have already searched, but as I do not know exactly which terms to use for such a 
search, I have not found anything yet.
I'll write my own PerlFixupHandler or so to do this if I have to, but if it already 
exists, I would not bother.


Re: serve items in "lib" or "PATH" fashion

Posted by André Warnier <aw...@ice-sa.com>.
Josh Narins wrote:
> 
> Josh Narins
> Director of Application Development
> SeniorBridge
> 
> 845 Third Ave
> 7th Floor
> New York, NY 10022
> Tel: (212) 994-6194
> Mobile: (917) 488-6248
> Fax: (212) 994-4260
> jnarins@seniorbridge.com
> 
> SeniorBridge
> Managing Complex Chronic Care
> http://www.seniorbridge.com
> 
> 
> SeniorBridge Statement of Confidentiality: The contents of this email message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. Any dissemination, distribution or copying of this email by an unintended or mistaken recipient is strictly prohibited. In said event, kindly reply to the sender and destroy all entries of this message and any attachments from your system. Thank you.-----Original Message-----
>> From: André Warnier [mailto:aw@ice-sa.com]
>> Sent: Tuesday, January 17, 2012 4:32 AM
>> To: mod_perl list
>> Subject: serve items in "lib" or "PATH" fashion
> 
> [snip]
> 
>> I have already searched, but as I do not know exactly which terms to
>> use for such a
>> search, I have not found anything yet.
>> I'll write my own PerlFixupHandler or so to do this if I have to, but
>> if it already
>> exists, I would not bother.
> 
> Not sure if there is a pre-made answer already for you, but you should handle the url -> file mapping with a PerlMapToStorageHandler.
> 
> That way (among other things?) Authen/Authz/Access and MIME are working with the right stuff.

Thanks.  I wasn't sure, and this will save me one bad iteration.


RE: serve items in "lib" or "PATH" fashion

Posted by Josh Narins <jn...@seniorbridge.com>.
>

Josh Narins
Director of Application Development
SeniorBridge

845 Third Ave
7th Floor
New York, NY 10022
Tel: (212) 994-6194
Mobile: (917) 488-6248
Fax: (212) 994-4260
jnarins@seniorbridge.com

SeniorBridge
Managing Complex Chronic Care
http://www.seniorbridge.com


SeniorBridge Statement of Confidentiality: The contents of this email message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. Any dissemination, distribution or copying of this email by an unintended or mistaken recipient is strictly prohibited. In said event, kindly reply to the sender and destroy all entries of this message and any attachments from your system. Thank you.-----Original Message-----
> From: André Warnier [mailto:aw@ice-sa.com]
> Sent: Tuesday, January 17, 2012 4:32 AM
> To: mod_perl list
> Subject: serve items in "lib" or "PATH" fashion

[snip]

> I have already searched, but as I do not know exactly which terms to
> use for such a
> search, I have not found anything yet.
> I'll write my own PerlFixupHandler or so to do this if I have to, but
> if it already
> exists, I would not bother.

Not sure if there is a pre-made answer already for you, but you should handle the url -> file mapping with a PerlMapToStorageHandler.

That way (among other things?) Authen/Authz/Access and MIME are working with the right stuff.

Re: serve items in "lib" or "PATH" fashion

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, Jan 17, 2012 at 10:02 AM, André Warnier <aw...@ice-sa.com> wrote:
> But isn't there an error in the examples shown ?
>
> RewriteCond         /your/docroot/dir1/%{REQUEST_FILENAME}  -f
> RewriteRule  ^(.+)  /your/docroot/dir1/$1  [L]
>
> If the original URL is e.g. "/cgi-bin/myscript.pl", and I wanted to check
> the local directory "/cgi-local" first, then this would evaluate to
>
> RewriteCond         /my/docroot/cgi-local/myscript.pl  -f
> but the "^(.+)" of the second line would evaluate to "/cgi-bin/myscript.pl"
> which would give a final URL of :
> "/my/docroot/cgi-local/cgi-bin/myscript.pl"
> which is probably not what I want.

It's kind of out-of-scope for the mod_perl list, but I think
REQUEST_FILENAME is the whole path.  Check the docs.

Regardless of the details, you seem to grasp how to make it work using
a -f RewriteCond, so play around with it until you get what you want.

- Perrin

Re: serve items in "lib" or "PATH" fashion

Posted by André Warnier <aw...@ice-sa.com>.
Perrin Harkins wrote:
> On Tue, Jan 17, 2012 at 4:31 AM, André Warnier <aw...@ice-sa.com> wrote:
>> E.g. I would be happy if I could write this in the Apache configuration :
>>
>> ScriptAlias /cgi-bin/ /var/www/site1/cgi-bin/;/var/www/global/cgi-bin/
>>
>> and have Apache look first in the local one, then in the global one each
>> time it is looking for a given script.  And similarly for other documents
>> like javascript libraries.
> 
> Use mod_rewrite.  See "Search pages in more than one directory":
> http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
> 
Thanks, Perrin.
I didn't know mod_rewrite could to do that.

But isn't there an error in the examples shown ?

RewriteCond         /your/docroot/dir1/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.+)  /your/docroot/dir1/$1  [L]

If the original URL is e.g. "/cgi-bin/myscript.pl", and I wanted to check the local 
directory "/cgi-local" first, then this would evaluate to

RewriteCond         /my/docroot/cgi-local/myscript.pl  -f
but the "^(.+)" of the second line would evaluate to "/cgi-bin/myscript.pl"
which would give a final URL of : "/my/docroot/cgi-local/cgi-bin/myscript.pl"
which is probably not what I want.

Instead, should the example rule not be something like :

RewriteRule  ^.*$  /dir1/%{REQUEST_FILENAME}  [L]

?

Re: serve items in "lib" or "PATH" fashion

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, Jan 17, 2012 at 4:31 AM, André Warnier <aw...@ice-sa.com> wrote:
> E.g. I would be happy if I could write this in the Apache configuration :
>
> ScriptAlias /cgi-bin/ /var/www/site1/cgi-bin/;/var/www/global/cgi-bin/
>
> and have Apache look first in the local one, then in the global one each
> time it is looking for a given script.  And similarly for other documents
> like javascript libraries.

Use mod_rewrite.  See "Search pages in more than one directory":
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

- Perrin