Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

serve items in "lib" or "PATH" fashion

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


aw at ice-sa

Jan 17, 2012, 1:31 AM

Post #1 of 6 (506 views)
Permalink
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.


jnarins at seniorbridge

Jan 17, 2012, 5:58 AM

Post #2 of 6 (489 views)
Permalink
RE: serve items in "lib" or "PATH" fashion [In reply to]

>

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 [at] seniorbridge

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 [at] ice-sa]
> 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.


aw at ice-sa

Jan 17, 2012, 6:07 AM

Post #3 of 6 (483 views)
Permalink
Re: serve items in "lib" or "PATH" fashion [In reply to]

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 [at] seniorbridge
>
> 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 [at] ice-sa]
>> 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.


perrin at elem

Jan 17, 2012, 6:20 AM

Post #4 of 6 (484 views)
Permalink
Re: serve items in "lib" or "PATH" fashion [In reply to]

On Tue, Jan 17, 2012 at 4:31 AM, André Warnier <aw [at] ice-sa> 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


aw at ice-sa

Jan 17, 2012, 7:02 AM

Post #5 of 6 (478 views)
Permalink
Re: serve items in "lib" or "PATH" fashion [In reply to]

Perrin Harkins wrote:
> On Tue, Jan 17, 2012 at 4:31 AM, André Warnier <aw [at] ice-sa> 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]

?


perrin at elem

Jan 17, 2012, 10:16 AM

Post #6 of 6 (480 views)
Permalink
Re: serve items in "lib" or "PATH" fashion [In reply to]

On Tue, Jan 17, 2012 at 10:02 AM, André Warnier <aw [at] ice-sa> 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

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.