You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John Chiu <jc...@IMPRIVATA.com> on 2003/08/22 20:24:00 UTC

problem with mod_perl 2.0 + apache 2.0 and proxyreq

Thanks in advance. I've tried all the archives and google'd but I have
not found anything that would help.

 

I'm running RH 8.0, httpd-2.0.40-11.5 and mod_perl-1.99_05-3 from the
RedHat distribution. I'm trying to create a small proxy module that will
check a non-proxy request and depending on "stuff" dynamically transform
it into a proxy request using mod_proxy.

 

 

I'm following the example in Chapter 7 (page 370) of the "Writing Apache
Modules with Perl and C". I know that the book is based on the older
apache 1.3 server and associated mod_perl. However, I have not found
anything in my readings to indicate that this would not work any more.

 

My version of the proxy module from the book is :

 

package ProxyTest;

 

use strict;

 

use warnings;

 

use Apache::RequestRec (); # for $r->content_type

 

use Apache::Const -compile =3D> 'OK';

 

use Apache::Const -compile =3D> 'DECLINED';

 

#use Apache::RequestUtil ();

 

sub handler

 

{

 

    my $r =3D shift;

 

    return Apache::DECLINED if $r->proxyreq;

 

    # set proxy to true

 

    $r->proxyreq(1);

 

    my $uri =3D $r->uri;

 

    # reset URI for mod_proxy

 

    my $newUri =3D 'http://test/goodbye.html';

 

    $r->uri($newUri);

 

    $r->filename("proxy:$newUri");

 

    # change handler to mod_proxy

 

    $r->handler('proxy-server');

 

    return Apache::OK;

 

}

 

1;

 

When I hit the "test" server, I fail with:

 

Proxy Error

 

 

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET
http://test/goodbye.html.=20

 

Reason: Max-Forwards has reached zero - proxy loop?

 

Additionally, a 502 Bad Gateway error was encountered while trying to
use an ErrorDocument to handle the request.

 

The apache error log indicates (with some debugging) that it is looping
on the "GET" of goodbye.html. Additional debuging indicates that
$r->proxyreq is always 0, so it's looping. My questions are:

 

1.    Did sometime change in apache 2 or mod_perl 2 so that you cannot

set proxyreq anymore: ie. $r->proxyreq(1).

2.    How do you set proxyreq if $r->proxyreq(1) is not the correct

method?

3.    Is the logic wrong in this proxy example?

 

Thanks again. Any help is appreciated.

 

John


Re: problem with mod_perl 2.0 + apache 2.0 and proxyreq

Posted by Stas Bekman <st...@stason.org>.
John Chiu wrote:
> Thanks in advance. I've tried all the archives and google'd but I have 
> not found anything that would help.
> 
>  
> 
> I'm running RH 8.0, httpd-2.0.40-11.5 and mod_perl-1.99_05-3 from the 
> RedHat distribution. I'm trying to create a small proxy module that will 
> check a non-proxy request and depending on "stuff" dynamically transform 
> it into a proxy request using mod_proxy.

1.99_05 is a way too old. Lots of bugs were fixed since that release. Upgrade 
to at least 1.99_09 or better the current cvs. 1.99_10 will be released as 
soon as perl-5.8.1 is released.

> I'm following the example in Chapter 7 (page 370) of the "Writing Apache 
> Modules with Perl and C". I know that the book is based on the older 
> apache 1.3 server and associated mod_perl. However, I have not found 
> anything in my readings to indicate that this would not work any more.

>     my $r =3D shift;
[... code snipped ...]

BTW, you mailer has mangled the source code, s/=/=3D/

> Additionally, a 502 Bad Gateway error was encountered while trying to 
> use an ErrorDocument to handle the request.
> 
>  
> 
> The apache error log indicates (with some debugging) that it is looping 
> on the "GET" of goodbye.html. Additional debuging indicates that 
> $r->proxyreq is always 0, so it's looping. My questions are:
> 
>  
> 
> 1.    Did sometime change in apache 2 or mod_perl 2 so that you cannot
> 
> set proxyreq anymore: ie. $r->proxyreq(1).
> 
> 2.    How do you set proxyreq if $r->proxyreq(1) is not the correct
> 
> method?
> 
> 3.    Is the logic wrong in this proxy example?

How can we possible know what the problem is if you don't show the relevant 
configuration section? Most likely you have a broken configuration and should 
advise first the mod_proxy documentation.
http://httpd.apache.org/docs-2.0/mod/mod_proxy.html

To make sure that the problem is not in mod_perl, I've added a new 
modules/proxy test to the mp2 test suite, based on that example from the eagle 
book. Try it and if you succeed to break it, then we will fix it. You will 
need to retrieve the cvs version in order to get it.
http://perl.apache.org/download/source.html#Development_mod_perl_2_0_Source_Distribution
(note: I have just committed the test, so if you use the snapshot, which is 
updated every 6 hours, it may not be there, so use the normal cvs checkout)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html