Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: mod_perl - separate PERL interpreter for each LocationMatch

Posted on 2011-09-12 09:22:57 by utham hoode

--_32c6384b-d9ee-4ae9-9752-cda1911e339e_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable


Hi All=2C I have written a mod_perl proxy server which redirects th=
e HTTP traffic to a webserver. I have pasted the snippet below. In =
the apache worker thread=2C is enable. In the httpd.conf two <LocationMatch=
> are configured http://ipaddress/path1/http://ipaddress/path2/ After start=
ing the http server if i open any URL from the browser=2C same =93TEST_VAR=
=94 is being printedfor both the URLs. If I call path1 first=2C then for bo=
th the URLs 100 is printed.If I call path2 first=2C then for both the URLs =
200 is printed.(that is its taking the first called Path=2C after httpd is =
started) #----------------------------Startup.pl --------------------------=
------------------##startup.pl use lib qw(/home/test1/libs)=3B 1=3B #------=
--------------------------- #---------------------------- httpd.conf-------=
--------------------------------------# # httpd.conf PerlRequire /home/tes=
t1/startup.pl #http://ipaddress/path1/<LocationMatch /path1/> SetEnvIf =
Request_URI "/" TEST_VAR=3D100 SetHandler perl-script PerlResponseH=
andler Module::Test</LocationMatch> #http://ipaddress/path2/<LocationMatch =
/path2/> SetEnvIf Request_URI "/" TEST_VAR=3D200 SetHandler perl-sc=
ript PerlResponseHandler Module::Test</LocationMatch> #----------------=
------------------------------------------------------------ ---# #--------=
-------------------- Test.pm ---------------------------------------------#=
# Test.pm package Module::Test=3B use strict=3B use Apache2::Const qw(:met=
hods :http :common)=3Buse Apache2::Log ()=3Buse Apache2::URI ()=3B my $par=
am =3D env_variable()=3B sub handler{ Apache2::ServerRec::warn($param)=
=3B print "Value".$param=3B return Apache2::Const::OK=3B} sub env_vari=
able{ # Configuration loading from a file during startup my $en=
dpointURL =3D $ENV{'TEST_VAR'}=3B return $endpointURL=3B} 1=3B #-----=
------------------------------------------------------------ ---------------=
But I tried with <VirtualHost> option and it is working fine as PerlOptio=
ns +Parent is present.But since the port numbers are different firefox will=
now allow simulataneous access toboth URL from same webpage. #http://ipad=
dress:8080/path1/<VirtualHost *:8080> SetEnvIf Request_URI "/" TEST_VAR=
=3D100 PerlRequire /home/test1/startup.pl PerlOptions +Parent <L=
ocationMatch /path2/> SetHandler perl-script PerlResponse=
Handler Module::Test </LocationMatch></VirtualHost> #http://ipaddress:=
8085/path2/<VirtualHost *:8085> SetEnvIf Request_URI "/" TEST_VAR=3D200 =
PerlRequire /home/test1/startup.pl PerlOptions +Parent <Location=
Match /path2/> SetHandler perl-script PerlResponseHandler=
Module::Test </LocationMatch></VirtualHost> Please help me with this=
=2C Thanks in advance.Regards=2Cuttam =

--_32c6384b-d9ee-4ae9-9752-cda1911e339e_
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
..hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 10pt=3B
font-family:Tahoma
}
--></style>
</head>
<body class=3D'hmmessage'><div dir=3D'ltr'>
<div><p class=3D"MsoNormal"><p class=3D"MsoNormal"><font class=3D"Apple-sty=
le-span" face=3D"Tahoma" size=3D"2">Hi All=2C</font></p><p class=3D"MsoNorm=
al"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &n=
bsp=3B &nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style=
-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B I have written a mod_pe=
rl proxy server which redirects the HTTP traffic to a webserver.</font></p>=
<p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" siz=
e=3D"2">&nbsp=3B &nbsp=3B I have pasted the snippet below. &nbsp=3B</font><=
/p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" =
size=3D"2">&nbsp=3B &nbsp=3B In the apache worker thread=2C is enable. In t=
he httpd.conf two &lt=3BLocationMatch&gt=3B are configured</font></p><p cla=
ss=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2=
">&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span=
" face=3D"Tahoma" size=3D"2">http://ipaddress/path1/</font></p><p class=3D"=
MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">http=
://ipaddress/path2/</font></p><p class=3D"MsoNormal"><font class=3D"Apple-s=
tyle-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNor=
mal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">After star=
ting the http server if i open any URL from the browser=2C same =93TEST_VAR=
=94 is being printed</font></p><p class=3D"MsoNormal"><font class=3D"Apple-=
style-span" face=3D"Tahoma" size=3D"2">for both the URLs.</font></p><p clas=
s=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"=
>&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span"=
face=3D"Tahoma" size=3D"2">If I call path1 first=2C then for both the URLs=
100 is printed.</font></p><p class=3D"MsoNormal"><font class=3D"Apple-styl=
e-span" face=3D"Tahoma" size=3D"2">If I call path2 first=2C then for both t=
he URLs 200 is printed.</font></p><p class=3D"MsoNormal"><font class=3D"App=
le-style-span" face=3D"Tahoma" size=3D"2">(that is its taking the first cal=
led Path=2C after httpd is started)</font></p><p class=3D"MsoNormal"><font =
class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p=
class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=
=3D"2">#----------------------------Startup.pl ----------------------------=
----------------#</font></p><p class=3D"MsoNormal"><font class=3D"Apple-sty=
le-span" face=3D"Tahoma" size=3D"2">#startup.pl</font></p><p class=3D"MsoNo=
rmal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B<=
/font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"T=
ahoma" size=3D"2">use lib qw(/home/test1/libs)=3B</font></p><p class=3D"Mso=
Normal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=
=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=
=3D"Tahoma" size=3D"2">1=3B</font></p><p class=3D"MsoNormal"><font class=3D=
"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=
=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">=
#---------------------------------</font></p><p class=3D"MsoNormal"><font c=
lass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p =
class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=
=3D"2">#---------------------------- httpd.conf----------------------------=
-----------------#</font></p><p class=3D"MsoNormal"><font class=3D"Apple-st=
yle-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNorm=
al"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</f=
ont></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tah=
oma" size=3D"2"># httpd.conf</font></p><p class=3D"MsoNormal"><font class=
=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p clas=
s=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"=
>PerlRequire /home/test1/startup.pl</font></p><p class=3D"MsoNormal"><font =
class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p=
class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=
=3D"2">#http://ipaddress/path1/</font></p><p class=3D"MsoNormal"><font clas=
s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&lt=3BLocationMatch /path=
1/&gt=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" =
face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3BSetEnvIf Request_URI "=
/" TEST_VAR=3D100</font></p><p class=3D"MsoNormal"><font class=3D"Apple-sty=
le-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3BSetHandler pe=
rl-script</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span"=
face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3BPerlResponseHandler M=
odule::Test</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-spa=
n" face=3D"Tahoma" size=3D"2">&lt=3B/LocationMatch&gt=3B</font></p><p class=
=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">=
&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" =
face=3D"Tahoma" size=3D"2">#http://ipaddress/path2/</font></p><p class=3D"M=
soNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&lt=
=3BLocationMatch /path2/&gt=3B</font></p><p class=3D"MsoNormal"><font class=
=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3B=
SetEnvIf Request_URI "/" TEST_VAR=3D200</font></p><p class=3D"MsoNormal"><f=
ont class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B=
&nbsp=3BSetHandler perl-script</font></p><p class=3D"MsoNormal"><font clas=
s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=
=3BPerlResponseHandler Module::Test</font></p><p class=3D"MsoNormal"><font =
class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&lt=3B/LocationMatch&=
gt=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" fac=
e=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font cla=
ss=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">#-----------------------=
--------------------------------------------------------#</font></p><p clas=
s=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2"=
>&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span"=
face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font=
class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">#-------------------=
--------- Test.pm ---------------------------------------------#</font></p>=
<p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" siz=
e=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-styl=
e-span" face=3D"Tahoma" size=3D"2"># Test.pm</font></p><p class=3D"MsoNorma=
l"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</fo=
nt></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Taho=
ma" size=3D"2">package Module::Test=3B</font></p><p class=3D"MsoNormal"><fo=
nt class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p=
><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" si=
ze=3D"2">use strict=3B</font></p><p class=3D"MsoNormal"><font class=3D"Appl=
e-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"Mso=
Normal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">use Apa=
che2::Const qw(:methods :http :common)=3B</font></p><p class=3D"MsoNormal">=
<font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">use Apache2::Lo=
g ()=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" f=
ace=3D"Tahoma" size=3D"2">use Apache2::URI ()=3B</font></p><p class=3D"MsoN=
ormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B=
</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"=
Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D=
"Apple-style-span" face=3D"Tahoma" size=3D"2">my $param =3D env_variable()=
=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=
=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font clas=
s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">sub handler</font></p><p =
class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=
=3D"2">{</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" =
face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font =
class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3BApac=
he2::ServerRec::warn($param)=3B</font></p><p class=3D"MsoNormal"><font clas=
s=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3Bprint "V=
alue".$param=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style=
-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3Breturn Apache2::Const::O=
K=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=
=3D"Tahoma" size=3D"2">}</font></p><p class=3D"MsoNormal"><font class=3D"Ap=
ple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"M=
soNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=
=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=
=3D"Tahoma" size=3D"2">sub env_variable</font></p><p class=3D"MsoNormal"><f=
ont class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">{</font></p><p cl=
ass=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"=
2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-spa=
n" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3B # Configuration lo=
ading from a file during startup</font></p><p class=3D"MsoNormal"><font cla=
ss=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p cl=
ass=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"=
2">&nbsp=3B &nbsp=3B &nbsp=3B my $endpointURL =3D $ENV{'TEST_VAR'}=3B</font=
></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma=
" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple=
-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3B return $=
endpointURL=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-=
span" face=3D"Tahoma" size=3D"2">}</font></p><p class=3D"MsoNormal"><font c=
lass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p =
class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=
=3D"2">1=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-spa=
n" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><fo=
nt class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">#-----------------=
------------------------------------------------------------ ---</font></p><=
p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=
=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style=
-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal"=
><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">But I tried wi=
th &lt=3BVirtualHost&gt=3B option and it is working fine as PerlOptions +Pa=
rent is present.</font></p><p class=3D"MsoNormal"><font class=3D"Apple-styl=
e-span" face=3D"Tahoma" size=3D"2">But since the port numbers are different=
firefox will now allow simulataneous access to</font></p><p class=3D"MsoNo=
rmal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">both URL =
from same webpage.</font></p><p class=3D"MsoNormal"><font class=3D"Apple-st=
yle-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNorm=
al"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</f=
ont></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tah=
oma" size=3D"2">#http://ipaddress:8080/path1/</font></p><p class=3D"MsoNorm=
al"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&lt=3BVirtu=
alHost *:8080&gt=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-s=
tyle-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B SetEnvIf Request_UR=
I "/" TEST_VAR=3D100</font></p><p class=3D"MsoNormal"><font class=3D"Apple-=
style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B PerlRequire /home/=
test1/startup.pl</font></p><p class=3D"MsoNormal"><font class=3D"Apple-styl=
e-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"MsoNormal=
"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbs=
p=3B PerlOptions +Parent</font></p><p class=3D"MsoNormal"><font class=3D"Ap=
ple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3B&lt=3B=
LocationMatch /path2/&gt=3B</font></p><p class=3D"MsoNormal"><font class=3D=
"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3B &n=
bsp=3B &nbsp=3B SetHandler perl-script</font></p><p class=3D"MsoNormal"><fo=
nt class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B =
&nbsp=3B &nbsp=3B &nbsp=3B PerlResponseHandler Module::Test</font></p><p cl=
ass=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"=
2">&nbsp=3B &nbsp=3B &nbsp=3B&lt=3B/LocationMatch&gt=3B</font></p><p class=
=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">=
&lt=3B/VirtualHost&gt=3B</font></p><p class=3D"MsoNormal"><font class=3D"Ap=
ple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D"M=
soNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=
=3B</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=
=3D"Tahoma" size=3D"2">#http://ipaddress:8085/path2/</font></p><p class=3D"=
MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&lt=
=3BVirtualHost *:8085&gt=3B</font></p><p class=3D"MsoNormal"><font class=3D=
"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B SetEnvIf Re=
quest_URI "/" TEST_VAR=3D200</font></p><p class=3D"MsoNormal"><font class=
=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B PerlRequ=
ire /home/test1/startup.pl</font></p><p class=3D"MsoNormal"><font class=3D"=
Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p class=3D=
"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nb=
sp=3B &nbsp=3B PerlOptions +Parent</font></p><p class=3D"MsoNormal"><font c=
lass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &nbs=
p=3B&lt=3BLocationMatch /path2/&gt=3B</font></p><p class=3D"MsoNormal"><fon=
t class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B &nbsp=3B &=
nbsp=3B &nbsp=3B &nbsp=3B SetHandler perl-script</font></p><p class=3D"MsoN=
ormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B=
&nbsp=3B &nbsp=3B &nbsp=3B &nbsp=3B PerlResponseHandler Module::Test</font=
></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma=
" size=3D"2">&nbsp=3B &nbsp=3B &nbsp=3B&lt=3B/LocationMatch&gt=3B</font></p=
><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" si=
ze=3D"2">&lt=3B/VirtualHost&gt=3B</font></p><p class=3D"MsoNormal"><font cl=
ass=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p><p c=
lass=3D"MsoNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D=
"2">Please help me with this=2C Thanks in advance.</font></p><p class=3D"Ms=
oNormal"><font class=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">Regard=
s=2C</font></p><p class=3D"MsoNormal"><font class=3D"Apple-style-span" face=
=3D"Tahoma" size=3D"2">uttam</font></p><p class=3D"MsoNormal"><font class=
=3D"Apple-style-span" face=3D"Tahoma" size=3D"2">&nbsp=3B</font></p></p></d=
iv> </div></body>
</html>=

--_32c6384b-d9ee-4ae9-9752-cda1911e339e_--

Report this message

#2: Re: mod_perl - separate PERL interpreter for each LocationMatch

Posted on 2011-09-12 10:18:59 by torsten.foertsch

On Monday, 12 September 2011 09:22:57 utham hoode wrote:
> Hi All, I have written a mod_perl proxy server which redirects
> the HTTP traffic to a webserver. I have pasted the snippet below.=20
> In the apache worker thread, is enable. In the httpd.conf two
> <LocationMatch> are configured
> http://ipaddress/path1/http://ipaddress/path2/ After starting the
> http server if i open any URL from the browser, same âÂ=9CTEST_VAR=E2=
ÂÂ is
> being printedfor both the URLs. If I call path1 first, then for both
> the URLs 100 is printed.If I call path2 first, then for both the URLs
> 200 is printed.(that is its taking the first called Path, after httpd
> is started) #----------------------------Startup.pl
> --------------------------------------------##startup.pl use lib
> qw(/home/test1/libs); 1; #---------------------------------
> #----------------------------
> httpd.conf---------------------------------------------# #
> httpd.conf PerlRequire /home/test1/startup.pl
> #http://ipaddress/path1/<LocationMatch /path1/> SetEnvIf
> Request_URI "/" TEST_VAR=3D100 SetHandler perl-script =20
> PerlResponseHandler Module::Test</LocationMatch>
> #http://ipaddress/path2/<LocationMatch /path2/> SetEnvIf
> Request_URI "/" TEST_VAR=3D200 SetHandler perl-script =20
> PerlResponseHandler Module::Test</LocationMatch>
> #----------------------------------------------------------- ---------
> -----------# #---------------------------- Test.pm
> ---------------------------------------------# # Test.pm package
> Module::Test; use strict; use Apache2::Const qw(:methods :http
> :common);use Apache2::Log ();use Apache2::URI (); my $param =3D
> env_variable(); sub handler{ Apache2::ServerRec::warn($param); =20
> print "Value".$param; return Apache2::Const::OK;} sub
> env_variable{ # Configuration loading from a file during
> startup my $endpointURL =3D $ENV{'TEST_VAR'}; return
> $endpointURL;} 1;
> #----------------------------------------------------------- ---------
> ------------ But I tried with <VirtualHost> option and it is working
> fine as PerlOptions +Parent is present.But since the port numbers are
> different firefox will now allow simulataneous access toboth URL from
> same webpage. #http://ipaddress:8080/path1/<VirtualHost *:8080> =20
> SetEnvIf Request_URI "/" TEST_VAR=3D100 PerlRequire
> /home/test1/startup.pl PerlOptions +Parent <LocationMatch
> /path2/> SetHandler perl-script PerlResponseHandler
> Module::Test </LocationMatch></VirtualHost>=20
> #http://ipaddress:8085/path2/<VirtualHost *:8085> SetEnvIf
> Request_URI "/" TEST_VAR=3D200 PerlRequire /home/test1/startup.pl =20
> PerlOptions +Parent <LocationMatch /path2/> SetHandler
> perl-script PerlResponseHandler Module::Test =20
> </LocationMatch></VirtualHost> Please help me with this, Thanks in
> advance.Regards,uttam

Could you please resend the mail with proper line breaks? Otherwise, it's=20
indecipherable, at least for me.

Torsten Förtsch

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

Like fantasy? http://kabatinte.net

Report this message

#3: RE: mod_perl - separate PERL interpreter for each LocationMatch

Posted on 2011-09-12 11:04:35 by utham hoode

Hi All=2C

I have written a mod_perl proxy server which redirects the HTTP traffic to
a webserver.
In the apache worker thread is enable. In the httpd.conf two
are configured
http://ipaddress/path1/
http://ipaddress/path2/
After starting the http server if i open any URL from the browser same
TEST_VAR is being printed
for both the URLs.
If I call path1 first then for both the URLs 100 is printed.
If I call path2 first then for both the URLs 200 is printed.

#startup.pl
use lib qw(/home/test1/libs)=3B
1=3B

#---------------------------------

# httpd.conf
PerlRequire /home/test1/startup.pl
#http://ipaddress/path1/

SetEnvIf Request_URI "/" TEST_VAR=3D100
SetHandler perl-script
PerlResponseHandler Module::Test

#http://ipaddress/path2/

SetEnvIf Request_URI "/" TEST_VAR=3D200
SetHandler perl-script
PerlResponseHandler Module::Test


#Test.pm
#----------------------------------------------------------- ---------
package Module::Test=3B
use strict=3B
use Apache2::Const qw(:methods :http :common)=3B
use Apache2::Log ()=3B
use Apache2::URI ()=3B

my $param =3D env_variable()=3B
sub handler
{
Apache2::ServerRec::warn($param)=3B
print "Value".$param=3B
return Apache2::Const::OK=3B
}

sub env_variable
{
# Configuration loading from a file during startup
my $endpointURL =3D $ENV{'TEST_VAR'}=3B
return $endpointURL=3B
}
1=3B
#----------------------------------------------------------- ---------------=
------

But I tried with option and it is working fine as PerlOptions
+Parent is present.
But since the port numbers are different firefox will now allow simulataneo=
us
access to
both URL from same webpage.

#http://ipaddress:8080/path1/

SetEnvIf Request_URI "/" TEST_VAR=3D100
PerlRequire /home/test1/startup.pl
PerlOptions +Parent

SetHandler perl-script
PerlResponseHandler Module::Test



#http://ipaddress:8085/path2/

SetEnvIf Request_URI "/" TEST_VAR=3D200
PerlRequire /home/test1/startup.pl
PerlOptions +Parent

SetHandler perl-script
PerlResponseHandler Module::Test



Regards=2C
uttam


----------------------------------------
> From: torsten.foertsch@gmx.net
> To: modperl@perl.apache.org
> Subject: Re: mod_perl - separate PERL interpreter for each LocationMatch
> Date: Mon=2C 12 Sep 2011 10:18:59 +0200
> CC: uttamhoode@live.com
>
> On Monday=2C 12 September 2011 09:22:57 utham hoode wrote:
> > Hi All=2C I have written a mod_perl proxy server which redirects
> > the HTTP traffic to a webserver. I have pasted the snippet below.
> > In the apache worker thread=2C is enable. In the httpd.conf two
> > are configured
> > http://ipaddress/path1/http://ipaddress/path2/ After starting the
> > http server if i open any URL from the browser=2C same =93TEST_VAR=94 i=
s
> > being printedfor both the URLs. If I call path1 first=2C then for both
> > the URLs 100 is printed.If I call path2 first=2C then for both the URLs
> > 200 is printed.(that is its taking the first called Path=2C after httpd
> > is started) #----------------------------Startup.pl
> > --------------------------------------------##startup.pl use lib
> > qw(/home/test1/libs)=3B 1=3B #---------------------------------
> > #----------------------------
> > httpd.conf---------------------------------------------# #
> > httpd.conf PerlRequire /home/test1/startup.pl
> > #http://ipaddress/path1/ SetEnvIf
> > Request_URI "/" TEST_VAR=3D100 SetHandler perl-script
> > PerlResponseHandler Module::Test
> > #http://ipaddress/path2/ SetEnvIf
> > Request_URI "/" TEST_VAR=3D200 SetHandler perl-script
> > PerlResponseHandler Module::Test
> > #----------------------------------------------------------- ---------
> > -----------# #---------------------------- Test.pm
> > ---------------------------------------------# # Test.pm package
> > Module::Test=3B use strict=3B use Apache2::Const qw(:methods :http
> > :common)=3Buse Apache2::Log ()=3Buse Apache2::URI ()=3B my $param =3D
> > env_variable()=3B sub handler{ Apache2::ServerRec::warn($param)=3B
> > print "Value".$param=3B return Apache2::Const::OK=3B} sub
> > env_variable{ # Configuration loading from a file during
> > startup my $endpointURL =3D $ENV{'TEST_VAR'}=3B return
> > $endpointURL=3B} 1=3B
> > #----------------------------------------------------------- ---------
> > ------------ But I tried with option and it is working
> > fine as PerlOptions +Parent is present.But since the port numbers are
> > different firefox will now allow simulataneous access toboth URL from
> > same webpage. #http://ipaddress:8080/path1/
> > SetEnvIf Request_URI "/" TEST_VAR=3D100 PerlRequire
> > /home/test1/startup.pl PerlOptions +Parent > /path2/> SetHandler perl-s=
cript PerlResponseHandler
> > Module::Test
> > #http://ipaddress:8085/path2/ SetEnvIf
> > Request_URI "/" TEST_VAR=3D200 PerlRequire /home/test1/startup.pl
> > PerlOptions +Parent SetHandler
> > perl-script PerlResponseHandler Module::Test
> > Please help me with this=2C Thanks in
> > advance.Regards=2Cuttam
>
> Could you please resend the mail with proper line breaks? Otherwise=2C it=
's
> indecipherable=2C at least for me.
>
> Torsten F=F6rtsch
>
> --
> Need professional modperl support? Hire me! (http://foertsch.name)
>
> Like fantasy? http://kabatinte.net =

Report this message

#4: Re: mod_perl - separate PERL interpreter for each LocationMatch

Posted on 2011-09-12 11:52:57 by torsten.foertsch

On Monday, 12 September 2011 11:04:35 utham hoode wrote:
> I have written a mod_perl proxy server which redirects the HTTP
> traffic to a webserver.
> In the apache worker thread is enable. In the httpd.conf two
> are configured
> http://ipaddress/path1/
> http://ipaddress/path2/
> After starting the http server if i open any URL from the browser same
> TEST_VAR is being printed
> for both the URLs.
> If I call path1 first then for both the URLs 100 is printed.
> If I call path2 first then for both the URLs 200 is printed.

I am still a bit at a loss what you are trying to do here. The phrase=20
"modperl proxy server that redirects" is quite ambiguous:

=2D a modperl handler that works in the response phase, mangles the request=
=20
a bit before sending it to a backend server. On the way back the response=20
from the backend is again a bit mangled perhaps and sent to the client

=2D on the other hand it may be a server that sends out HTTP redirects to=20
point the browser to the correct server using HTTP 3xx codes.

=2D and thirdly it may be a piece of code working in a phase between=20
maptostorage and fixup that modifies the request configuration to have it
handled by mod_proxy.

=2D perhaps there are a few more possible meanings

Generally, apache creates an individual configuration for each request.=20
At first it looks up the virtual server config. Then it merges into that=20
one all the <Location> <Directory> <Files> blocks that are applicable.

So, you can set a certain environment variable for one request to value1=20
and for another to value2. But you have to have a distinguishing mark.

> #startup.pl
> use lib qw(/home/test1/libs);
> 1;
>=20
> #---------------------------------
>=20
> # httpd.conf
> PerlRequire /home/test1/startup.pl
> #http://ipaddress/path1/
>=20
> SetEnvIf Request_URI "/" TEST_VAR=3D100
> SetHandler perl-script
> PerlResponseHandler Module::Test
>=20
> #http://ipaddress/path2/
>=20
> SetEnvIf Request_URI "/" TEST_VAR=3D200
> SetHandler perl-script
> PerlResponseHandler Module::Test

In the snippet above I do not see any such mark. You set TEST_VAR to 100=20
and to 200 if the request URI is /. That does not make sense.

>=20
> #Test.pm
> #----------------------------------------------------------- ---------
> package Module::Test;
> use strict;
> use Apache2::Const qw(:methods :http :common);
> use Apache2::Log ();
> use Apache2::URI ();
>=20
> my $param =3D env_variable();

Here you use a global variable that is set only once for the lifetime of=20
the interpreter when the module is compiled. $param is not set for each=20
request.

> sub handler
> {
> Apache2::ServerRec::warn($param);
> print "Value".$param;
> return Apache2::Const::OK;
> }
>=20
> sub env_variable
> {
> # Configuration loading from a file during startup
> my $endpointURL =3D $ENV{'TEST_VAR'};
> return $endpointURL;
> }
> 1;
> #----------------------------------------------------------- ----------
> -----------
>=20
> But I tried with option and it is working fine as PerlOptions
> +Parent is present.
> But since the port numbers are different firefox will now allow
> simulataneous access to
> both URL from same webpage.
>=20
> #http://ipaddress:8080/path1/
>=20
> SetEnvIf Request_URI "/" TEST_VAR=3D100
> PerlRequire /home/test1/startup.pl
> PerlOptions +Parent
>=20
> SetHandler perl-script
> PerlResponseHandler Module::Test
>=20
>=20
>=20
> #http://ipaddress:8085/path2/
>=20
> SetEnvIf Request_URI "/" TEST_VAR=3D200
> PerlRequire /home/test1/startup.pl
> PerlOptions +Parent
>=20
> SetHandler perl-script
> PerlResponseHandler Module::Test

+Parent is a VHost level option like:

<VirtualHost ...>
PerlOptions +Parent
...
</VirtualHost>

The virtual host then gets it's own perl interpreter. It has been=20
requested a few times to make it possible to change the interpreter per=20
request configuration but nobody has got around to do the work yet.=20
Something along these lines would be good:

<PerlInterpreter MyInterpreter>
PerlSwitches ...
PerlRequire ...
PerlModule ...
</PerlInterpreter>

<PerlInterpreter OtherInterpreter>
PerlSwitches ...
PerlRequire ...
PerlModule ...
</PerlInterpreter>

<Location /...>
PerlUseInterpreter MyInterpreter
</Location>

Torsten F=F6rtsch

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

Like fantasy? http://kabatinte.net

Report this message

#5: RE: mod_perl - separate PERL interpreter for each LocationMatch

Posted on 2011-09-12 13:03:30 by utham hoode

----------------------------------------
> From: torsten.foertsch@gmx.net
> To: modperl@perl.apache.org
> Subject: Re: mod_perl - separate PERL interpreter for each LocationMatch
> Date: Mon=2C 12 Sep 2011 11:52:57 +0200
> CC: uttamhoode@live.com
>
> On Monday=2C 12 September 2011 11:04:35 utham hoode wrote:
> > I have written a mod_perl proxy server which redirects the HTTP
> > traffic to a webserver.
> > In the apache worker thread is enable. In the httpd.conf two
> > are configured
> > http://ipaddress/path1/
> > http://ipaddress/path2/
> > After starting the http server if i open any URL from the browser same
> > TEST_VAR is being printed
> > for both the URLs.
> > If I call path1 first then for both the URLs 100 is printed.
> > If I call path2 first then for both the URLs 200 is printed.
>
> I am still a bit at a loss what you are trying to do here. The phrase
> "modperl proxy server that redirects" is quite ambiguous:

Thanks for the quick response.
Sorry for not providing all the details. Actual proxy program is working fi=
ne withsingle <LocationMatch>. I wrote Test.pm just to demonstrate the issu=
e.

>
> - a modperl handler that works in the response phase=2C mangles the reque=
st
> a bit before sending it to a backend server. On the way back the response
> from the backend is again a bit mangled perhaps and sent to the client
>
> - on the other hand it may be a server that sends out HTTP redirects to
> point the browser to the correct server using HTTP 3xx codes.
>
> - and thirdly it may be a piece of code working in a phase between
> maptostorage and fixup that modifies the request configuration to have it
> handled by mod_proxy.
>
> - perhaps there are a few more possible meanings
>
> Generally=2C apache creates an individual configuration for each request.
> At first it looks up the virtual server config. Then it merges into that
> one all the <Location> <Directory> <Files> blocks that are applicable.
>
> So=2C you can set a certain environment variable for one request to value=
1
> and for another to value2. But you have to have a distinguishing mark.
>
> > #startup.pl
> > use lib qw(/home/test1/libs)=3B
> > 1=3B
> >
> > #---------------------------------
> >
> > # httpd.conf
> > PerlRequire /home/test1/startup.pl
> > #http://ipaddress/path1/
> >
> > SetEnvIf Request_URI "/" TEST_VAR=3D100
> > SetHandler perl-script
> > PerlResponseHandler Module::Test
> >
> > #http://ipaddress/path2/
> >
> > SetEnvIf Request_URI "/" TEST_VAR=3D200
> > SetHandler perl-script
> > PerlResponseHandler Module::Test
>
> In the snippet above I do not see any such mark. You set TEST_VAR to 100
> and to 200 if the request URI is /. That does not make sense.

I tried this but did not work.
SetEnvIf Request_URI "/path1/" TEST_VAR=3D100
and=A0
SetEnvIf Request_URI "/path2/" TEST_VAR=3D200


>
> >
> > #Test.pm
> > #----------------------------------------------------------- ---------
> > package Module::Test=3B
> > use strict=3B
> > use Apache2::Const qw(:methods :http :common)=3B
> > use Apache2::Log ()=3B
> > use Apache2::URI ()=3B
> >
> > my $param =3D env_variable()=3B
>
> Here you use a global variable that is set only once for the lifetime of
> the interpreter when the module is compiled. $param is not set for each
> request.


Here is the problem. Both path1 and path2 are sharing same global variable =
$param.Is there any way to avoid that?. Because In the actual proxy program=
I am reading aconfiguration file and storing it in a global variable. For =
path1 and path2=A0configuration file is different. I can place the variable=
inside sub handler {}so that for =A0each request program loads the configu=
ration file.I think this will reduce the performance.

>
> > sub handler
> > {
> > Apache2::ServerRec::warn($param)=3B
> > print "Value".$param=3B
> > return Apache2::Const::OK=3B
> > }
> >
> > sub env_variable
> > {
> > # Configuration loading from a file during startup
> > my $endpointURL =3D $ENV{'TEST_VAR'}=3B
> > return $endpointURL=3B
> > }
> > 1=3B
> > #----------------------------------------------------------- ----------
> > -----------
> >
> > But I tried with option and it is working fine as PerlOptions
> > +Parent is present.
> > But since the port numbers are different firefox will now allow
> > simulataneous access to
> > both URL from same webpage.
> >
> > #http://ipaddress:8080/path1/
> >
> > SetEnvIf Request_URI "/" TEST_VAR=3D100
> > PerlRequire /home/test1/startup.pl
> > PerlOptions +Parent
> >
> > SetHandler perl-script
> > PerlResponseHandler Module::Test
> >
> >
> >
> > #http://ipaddress:8085/path2/
> >
> > SetEnvIf Request_URI "/" TEST_VAR=3D200
> > PerlRequire /home/test1/startup.pl
> > PerlOptions +Parent
> >
> > SetHandler perl-script
> > PerlResponseHandler Module::Test
>
> +Parent is a VHost level option like:
>
> <VirtualHost ...>
> PerlOptions +Parent
> ...
> </VirtualHost>
>
> The virtual host then gets it's own perl interpreter. It has been
> requested a few times to make it possible to change the interpreter per
> request configuration but nobody has got around to do the work yet.
> Something along these lines would be good:
=A0   I wish below feature is supported.

>
> <PerlInterpreter MyInterpreter>
> PerlSwitches ...
> PerlRequire ...
> PerlModule ...
> </PerlInterpreter>
>
> <PerlInterpreter OtherInterpreter>
> PerlSwitches ...
> PerlRequire ...
> PerlModule ...
> </PerlInterpreter>
>
> <Location /...>
> PerlUseInterpreter MyInterpreter
> </Location>
>
> Torsten F=F6rtsch
>
> --
> Need professional modperl support? Hire me! (http://foertsch.name)
>
> Like fantasy? http://kabatinte.net
=

Report this message

#6: Re: mod_perl - separate PERL interpreter for each LocationMatch

Posted on 2011-09-12 13:36:36 by torsten.foertsch

On Monday, 12 September 2011 13:03:30 utham hoode wrote:
> Here is the problem. Both path1 and path2 are sharing same global
> variable $param.Is there any way to avoid that?. Because In the
> actual proxy program I am reading aconfiguration file and storing it
> in a global variable. For path1 and path2 configuration file is
> different. I can place the variable inside sub handler {}so that for
> each request program loads the configuration file.I think this will
> reduce the performance.

how about

=3Dhttpd.conf===============3D=3 D=====
==================== =3D
<LocationMatch "^/path1">
SetEnv CFG /path/to/config1.conf
</LocationMatch>

<LocationMatch "^/path2">
SetEnv CFG /path/to/config2.conf
</LocationMatch>
==================== =====3D=
==================== =====3D=
==

=3Dthe handler=================3D=3 D===
====================
my %config;

sub handler {
my ($r)=3D@_;

my $cfg=3D$r->subprocess_env->{CFG} or
die "No config file configured for ".$r->uri;
=20
$cfg=3D($config{$cfg}||=3Dread_cfg $cfg);
...
}
==================== =====3D=
==================== =====3D=
==

Thus, the global %config is used as a cache for the configurations of the=20
various URIs. The actual file is read only on the first request.

All the configurations can even be pre-populated at startup time.

Note however, that since the config is read only once it can be changed=20
only by starting up a new interpreter. If that's a problem you can=20
monitor file modification times for example. If I were you I'd use an=20
MMapDB object.

Torsten F=F6rtsch

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

Like fantasy? http://kabatinte.net

Report this message