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

Mailing List Archive: ModPerl: ModPerl

Perl section and request object

 

 

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


antoine at 7enlocation

Sep 19, 2007, 1:43 AM

Post #1 of 7 (3147 views)
Permalink
Perl section and request object

Hello,

I'm new to mod perl, I've setup an apache2 / MP2 on an linux debian etch
server.
I want to access in my apache conf to the HTML Request Header Host:

I've written this code :

NameVirtualHost 192.168.1.203
UseCanonicalName Off

PerlOptions +GlobalRequest

<Perl>
use Apache2::RequestUtil ();
my $r = Apache2::RequestUtil->request;
[...]
</Perl>

But when I restart the server I get the following error message
etch:~# /etc/init.d/apache2 restart
Forcing reload of web server (apache2)...Syntax error on line 7 of
/etc/apache2/sites-enabled/999-vhost:
\t(in cleanup) Global $r object is not available. Set:\n\tPerlOptions
+GlobalRequest\nin httpd.conf at /etc/apache2/sites-enabled/999-vhost line
9.\n
failed!

But I've already add PerlOptions +GlobalRequest ...

Has anyone got an idea ?

Thanks
--
View this message in context: http://www.nabble.com/Perl-section-and-request-object-tf4479522.html#a12773009
Sent from the mod_perl - General mailing list archive at Nabble.com.


deepfryed at gmail

Sep 19, 2007, 3:00 AM

Post #2 of 7 (3013 views)
Permalink
Re: Perl section and request object [In reply to]

me thinks that PerlOptions +GlobalRequest should be inside your <Directory>
or <Location> section.

http://perl.apache.org/docs/2.0/user/config/config.html#mod_perl_Directives_Argument_Types_and_Allowed_Location



On 9/19/07, antoine7 <antoine [at] 7enlocation> wrote:
>
>
> Hello,
>
> I'm new to mod perl, I've setup an apache2 / MP2 on an linux debian etch
> server.
> I want to access in my apache conf to the HTML Request Header Host:
>
> I've written this code :
>
> NameVirtualHost 192.168.1.203
> UseCanonicalName Off
>
> PerlOptions +GlobalRequest
>
> <Perl>
> use Apache2::RequestUtil ();
> my $r = Apache2::RequestUtil->request;
> [...]
> </Perl>
>
> But when I restart the server I get the following error message
> etch:~# /etc/init.d/apache2 restart
> Forcing reload of web server (apache2)...Syntax error on line 7 of
> /etc/apache2/sites-enabled/999-vhost:
> \t(in cleanup) Global $r object is not available. Set:\n\tPerlOptions
> +GlobalRequest\nin httpd.conf at /etc/apache2/sites-enabled/999-vhost line
> 9.\n
> failed!
>
> But I've already add PerlOptions +GlobalRequest ...
>
> Has anyone got an idea ?
>
> Thanks
> --
> View this message in context:
> http://www.nabble.com/Perl-section-and-request-object-tf4479522.html#a12773009
> Sent from the mod_perl - General mailing list archive at Nabble.com.
>
>


antoine at 7enlocation

Sep 19, 2007, 3:36 AM

Post #3 of 7 (3018 views)
Permalink
Re: Perl section and request object [In reply to]

I've just test, changing the directive to a <Directory> section in apache
conf, but I've always the same error.
--
View this message in context: http://www.nabble.com/Perl-section-and-request-object-tf4479522.html#a12774905
Sent from the mod_perl - General mailing list archive at Nabble.com.


mjhlists-modperl-20060801 at liminalflux

Sep 19, 2007, 7:24 AM

Post #4 of 7 (3000 views)
Permalink
Re: Perl section and request object [In reply to]

On Wednesday 19 September 2007 4:43:25 am antoine7 wrote:

> <Perl>
> use Apache2::RequestUtil ();
> my $r = Apache2::RequestUtil->request;
> [...]
> </Perl>
>
> But when I restart the server I get the following error message
> etch:~# /etc/init.d/apache2 restart
> Forcing reload of web server (apache2)...Syntax error on line 7 of
> /etc/apache2/sites-enabled/999-vhost:
> \t(in cleanup) Global $r object is not available. Set:\n\tPerlOptions
> +GlobalRequest\nin httpd.conf at /etc/apache2/sites-enabled/999-vhost line
> 9.\n
> failed!
>
> But I've already add PerlOptions +GlobalRequest ...
>
> Has anyone got an idea ?

$r is a request object. It only exists when you're processing a request, so
you can't use it during startup as there's no active request at that point.

What is it you are trying to do?


antoine at 7enlocation

Sep 19, 2007, 9:21 AM

Post #5 of 7 (3004 views)
Permalink
Re: Perl section and request object [In reply to]

I've an SVN server on the same machine, at each commit the svn server update
the changes to a local directory /www with this structure

/www/www.domain1.com.lan/trunk
/www/www.domain1.com.lan/tags/001
/www/www.domain1.com.lan/tags/002
...
/www/www.domain1.com.lan/branches/001
...
/www/www.subdomain.domain2.com.lan/trunk

etc

so I will have apache that point dynamicly to trunk / each tags / each
branches of each domain ... we have a lot of search engine optimisation on
our websites, that restrict us, if a website is on a / of the production
webserver it has to be too on the dev server.

I've configurated a local TLD zone ".lan" with a wildcard that point *.lan
demand to the apache developpement server.

if the production website is www.domain1.com
the local trunk is www.domain1.com.lan -> DocumentRoot 'll point to
/www/www.domain1.com.lan/trunk
the first branche is dev.001.domain1.com.lan -> DocumentRoot 'll point to
/www/www.domain1.com.lan/branches/000
the fisrt tag is ver.001.domain1.com.lan -> DocumentRoot 'll point to
/www/www.domain1.com.lan/tags/001

etc

I've all working, except I don't know what Host is asked by the developper
on the apache server, so I can't calculate a DocumentRoot to serve him the
correct pages

I've also try with VirtualDocumentRoot with no success, I'm an SEO Project
Architect I well known some languages but not a perl and I'm not an Apache
expert ...

There's the solution to read the /www directory and generate dynamicly some
VHost but the server will have to be restarted each time a directory is
added to /www ... it's not a good option in my point of view

antoine
--
View this message in context: http://www.nabble.com/Perl-section-and-request-object-tf4479522.html#a12780901
Sent from the mod_perl - General mailing list archive at Nabble.com.


gozer at ectoplasm

Sep 20, 2007, 12:02 AM

Post #6 of 7 (3011 views)
Permalink
Re: Perl section and request object [In reply to]

antoine7 wrote:
> I've an SVN server on the same machine, at each commit the svn server update
> the changes to a local directory /www with this structure
>
> [...]
>
> I've all working, except I don't know what Host is asked by the developper
> on the apache server,

You mean, $r->hostname ?
<http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_hostname_>

> so I can't calculate a DocumentRoot to serve him the
> correct pages
>
> I've also try with VirtualDocumentRoot with no success, I'm an SEO Project
> Architect I well known some languages but not a perl and I'm not an Apache
> expert ...

What you probably want to do is to implement your own MapToStorage handler
<http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlMapToStorageHandler>

It's not very hard, as all you need to do is to implement your own scheme
to map a servername+uri into a path on disk.

sub handler {
my $r = shirt;
my $host = $r->hostname;
my $uri = $r->uri;

[.... figure out if you care about this particular request ...]
[... otherwise, let apache do what it normally does ...]
return Apache2::Const::DECLINED unless $care;

[.... from $host + $uri, figure out where this should end up ...]
$r->filename("/some/calculated/path");

return Apache2::Const::OK;
}

> There's the solution to read the /www directory and generate dynamicly some
> VHost but the server will have to be restarted each time a directory is
> added to /www ... it's not a good option in my point of view

There are always graceful restarts to deal with that.
------------------------------------------------------------------------
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
Attachments: signature.asc (0.24 KB)


antoine at 7enlocation

Sep 20, 2007, 12:59 PM

Post #7 of 7 (3039 views)
Permalink
Re: Perl section and request object [In reply to]

Many thanks all,

I've phone to a local Sysop who give me a VirtualHost solution.
I'll take a look at mod-perl2 for some future project.

Antoine
--
View this message in context: http://www.nabble.com/Perl-section-and-request-object-tf4479522.html#a12804695
Sent from the mod_perl - General mailing list archive at Nabble.com.

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.