Running a mod_perl script at the domain root

Running a mod_perl script at the domain root

am 10.02.2008 21:58:26 von Matthew Tylee Atkinson

I've spent at least a couple of hours trying to figure this out and
reading manuals, to no avail, hence asking here. I hope it's not too
obvious :-).

I'm running a mod_perl (2.0.2) script from the root of my domain. My
Apache (2.2.3) configuration is as follows.


. . .
PerlOptions +Parent
PerlSwitches -T -I/var/www/testsite


SetHandler perl-script
PerlResponseHandler TestSite




My script takes the whole URI and uses that as part of the input to tell
it which part of the site the user wants to visit (such as / for the
home page or /account to manage their contact details).

The problem is that, because the script overrides the whole domain, a
request for /logo.png or the CSS file will not work properly.

I have tried using mod_rewrite to combat this, to no avail. I think the
problem is that when I was using mod_python on a different site (a
MoinMoin wiki as it happens), the handling of the request is different;
it'd be more like the following:

# map /wiki static files to Moin htdocs
RewriteRule ^/wiki/(.*)$ /var/www/agdev-wiki/htdocs/$1 [last]
# map everything else to server script
RewriteRule ^(.*)$ /var/www/agdev-wiki/moinmodpy.py$1

In this case, I can successfully use mod_rewrite because I can send the
request to a certain script. I can't see how to send the request to a
certain location, as would appear to be required by the mod_perl setup.

Could someone direct me to instructions or an example Apache config
where they're running a mod_perl script at the domain root?

Thanks very much for your time,

best regards,


P.S. My site is now running much faster under mod_perl (albeit without
CSS or a logo at the moment :-)) -- mod_perl really does seem to rock
maximally and I'm looking forward to getting it all working smoothly.
--
Matthew Tylee Atkinson

Re: Running a mod_perl script at the domain root

am 10.02.2008 22:47:04 von Adam Prime

There are a couple of ways you can tackle this sort of thing.

1) You can modify TestSite to return DECLINED for any request that you
want to be handled by the filesystem rather than your handler. ie

if $r->uri =~ m|\css$| {
return Apache2::Const::DECLINED;
}

2) If you've got all your CSS and images in directories dedicated to
those tasks, then you can add locations blocks that SetHandler
default-handler. ie:


SetHandler perl-script
PerlResponseHandler TestSite



SetHandler default-handler



SetHandler default-handler


There are likely other ways to handle it too.

Adam

Matthew Tylee Atkinson wrote:
> I've spent at least a couple of hours trying to figure this out and
> reading manuals, to no avail, hence asking here. I hope it's not too
> obvious :-).
>
> I'm running a mod_perl (2.0.2) script from the root of my domain. My
> Apache (2.2.3) configuration is as follows.
>
>
> . . .
> PerlOptions +Parent
> PerlSwitches -T -I/var/www/testsite
>
>
> SetHandler perl-script
> PerlResponseHandler TestSite
>

>

>
>
> My script takes the whole URI and uses that as part of the input to tell
> it which part of the site the user wants to visit (such as / for the
> home page or /account to manage their contact details).
>
> The problem is that, because the script overrides the whole domain, a
> request for /logo.png or the CSS file will not work properly.
>
> I have tried using mod_rewrite to combat this, to no avail. I think the
> problem is that when I was using mod_python on a different site (a
> MoinMoin wiki as it happens), the handling of the request is different;
> it'd be more like the following:
>
> # map /wiki static files to Moin htdocs
> RewriteRule ^/wiki/(.*)$ /var/www/agdev-wiki/htdocs/$1 [last]
> # map everything else to server script
> RewriteRule ^(.*)$ /var/www/agdev-wiki/moinmodpy.py$1
>
> In this case, I can successfully use mod_rewrite because I can send the
> request to a certain script. I can't see how to send the request to a
> certain location, as would appear to be required by the mod_perl setup.
>
> Could someone direct me to instructions or an example Apache config
> where they're running a mod_perl script at the domain root?
>
> Thanks very much for your time,
>
> best regards,
>
>
> P.S. My site is now running much faster under mod_perl (albeit without
> CSS or a logo at the moment :-)) -- mod_perl really does seem to rock
> maximally and I'm looking forward to getting it all working smoothly.

Re: Running a mod_perl script at the domain root

am 11.02.2008 14:57:08 von Matthew Tylee Atkinson

On Sun, 2008-02-10 at 16:47 -0500, Adam Prime wrote:
> 1) You can modify TestSite to return DECLINED for any request that you
> want to be handled by the filesystem rather than your handler. ie
>
.. . .
>
> 2) If you've got all your CSS and images in directories dedicated to
> those tasks, then you can add locations blocks that SetHandler
> default-handler. ie:
.. . .

Thanks very much for this! I went for the etc.
approach in the end as it seemed more suitable for my situation.

My site now seems a lot more alive :-).

best regards,


--
Matthew Tylee Atkinson