Re: WELCOME to modperl@perl.apache.org

Re: WELCOME to modperl@perl.apache.org

am 16.07.2010 14:24:17 von Hans de Groot

Hello,

I am trying to use the proxypass directive in mod_perl.

I actually got this working (after upgrading to mod_perl 2.4.x) so I
know it is possible to use proxy pass here
but I still have one problem.

I have a perl hander:

#file:ModPerl/VHost.pm
#-------------------------
package ModPerl::VHost;

use strict;

use Apache2::Const qw(OK DECLINED :options :override);
use Apache2::RequestRec ();
use Apache2::RequestUtil ();
use Apache2::ServerRec ();
use Apache2::ServerUtil ();
use Apache2::Access ();

use Mysql;

my $dbh_persistent = &set_up_connection();

sub handler {
my $r = shift;
my $s = $r->server();

# some code to decide which vhost we are.

# here is what I use:

$r->add_config( [
'ProxyPass http://www.exampledomain2.com/',
]
,~0,'/test'
);

# some more code.
----------------------------------------------

In my httpd.conf I use

PerlPostReadRequestHandler ModPerl::VHost

If I use this I can go to http://www.exampledomain1.com/test and I see
the contents from www.exampledomain2.com/

But when I change the last part to

$r->add_config( [
'ProxyPass http://www.exampledomain2.com/',
'AllowOverride Options AuthConfig',
]
,~0,'/'
);

I get segmentations faults.

If I change it to

,~0,''
);

I don't get segfault but I also do not get any porxy results. I just
see the default index.html

So how to I get it to proxypass everything for a certain domain (the
/location)?

I cannot use .htaccess files or server directives since this is done
on the fly. I do not want to reload my server config
every time a change is made and I think must be possible since other
locations (like the /test) do work.

ps I use:

httpd-2.2.3-11.el5_2.centos.4
mod_perl-2.0.4-6.el5


Thanks for any help.

Regards

Hans de Groot

Re: WELCOME to modperl@perl.apache.org

am 16.07.2010 15:29:38 von torsten.foertsch

On Friday 16 July 2010 14:24:17 Hans de Groot wrote:
> PerlPostReadRequestHandler ModPerl::VHost
>=20
I think this is too early in the request cycle to do that. Try a=20
PerlMapToStorageHandler. You may also have a look at Apache2::Translation. =
The=20
documentation needs a rewrite, I know. It's purpose is to keep most of the=
=20
config in a database or similar and to avoid to reload apache when it chang=
es.

You may also try to do in a PerlFixupHandler:

$r->proxyreq(2);
$r->filename('proxy:'.$url);
$r->handler('proxy_server');

Apache2::Translation does that to proxy requests. Another example could be =
the=20
implementation of fetch_url() in ModPerl2::Tools.

Torsten Förtsch

=2D-=20
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net

Re: add_config proxypass segfaults.

am 16.07.2010 21:36:47 von Hans de Groot

Hi,

Thank you for your reply.

I don't know why I never read about Apache2-Translation before but it
seems to do what I need.
But I am allready using my perl scripts and it's to late (to much
work) to change now. Maybe in the future.
When I have more time I am definetly going to experiment with it.

I did move the code to the PerlTransHandler and the
PerlMapToStorageHandler but the same effect.

I thought it had something to do with the / but now I only get
segfaults notmatter of I put slashes or not

I am sure I saw it working. I did get results before.

Anyway I an trying the PerlFixupHandler suggestion but I get this error:

failed to resolve handler `ModPerl::VHost_fixup': Bad name after
proxy_server' at /usr/lib/perl5/site_perl/ModPerl/VHost_fixup.pm line
26.\nCompilation failed in require at (eval 34) line 3.\n

So I guess I maybe missed some thing silly?

Do I need to add a proxy handler somewhere?

Below the handler code.

#file:ModPerl/VHost_fixup.pm
#-------------------------
package ModPerl::VHost_fixup;

use strict;

use Apache2::Const qw(OK DECLINED :options :override);
use Apache2::RequestRec ();
use APR::Finfo ();
use APR::Const -compile => qw(FINFO_NORM);

sub handler {
my $r = shift;
$r->proxyreq(2);
$r->filename('proxy:http://www.nu.nl/);
$r->handler('proxy_server');
return DECLINED;
}

1;




Hans de Groot d
Email: hansg@dandy.nl www: http://www.dandy.nl

Re: add_config proxypass segfaults.

am 16.07.2010 21:45:30 von Hans de Groot

Okay sorry my fault.

I missed a quote. in the line

$r->filename('proxy:http://www.nu.nl/);

Now it works perfectly.

Thank you very much for the golden tip. :-)