You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Mohit Anchlia <mo...@gmail.com> on 2008/07/10 17:58:54 UTC

[users@httpd] Re: Using rewrite to forward the request OR mod_perl

If somebody can try and answer my questions posted below would really help
me. I have been reading about other ways of re-directing the traffic and I
found mod_perl module could also help in doing that. Since I have not done
this before advise beforehand would make things clear.

On 7/9/08, Mohit Anchlia <mo...@gmail.com> wrote:
>
> We have a web server that redirects traffic to app server using mod_jk load
> balancer.
>
> Now I need to do the following:
>
> 1. If request comes from URL /AB and content of URL /AB has content in
> certain format then forward it to mod_jk otherwise forward it to some other
> URL (external system in our case).
> 2. Make sure that when apache forwards the requests to external URL,
> session from client is still active.
>
> My obvious questions are:
> 1. Can I do the above using rewrite rules?
> 2. Can I use perl in rewrite rules to parse through the content and somehow
> tell apache to re-direct the request? What's the best way to do that? In
> terms of performance, efficiency etc.
> 3. If rewrite forwards the request then does it still maintains the session
> from client -> WebServer -> External system?
>
> I need your advise.
>
>

Re: [users@httpd] Re: Using rewrite to forward the request OR mod_perl

Posted by Mohit Anchlia <mo...@gmail.com>.
By content I meant content that's being posted by the end user using
HttpPost. I need to look at that content to determine where that request
should go. So for eg: if a user fills the form and posts it I need to look
at the posted content to do the switching.

On Mon, Jul 14, 2008 at 2:45 PM, André Warnier <aw...@ice-sa.com> wrote:

> Mohit Anchlia wrote:
> [...]
>
>  We have a web server that redirects traffic to app server using mod_jk
>>> load
>>> balancer.
>>>
>>> Now I need to do the following:
>>>
>>> 1. If request comes from URL /AB and content of URL /AB has content in
>>> certain format then forward it to mod_jk otherwise forward it to some
>>> other
>>> URL (external system in our case).
>>>
>>
> I may be late with this answer, but for the first part above, you may be
> interested to know that there is an alternative to the "JkMount" directives,
> like this :
>
> <LocationMatch "/AB">
>  SetHandler jakarta-servlet
>  SetEnvIf REQUEST_URI "\.(htm|web|css|gif|jpg|js|html?)$" no-jk
>  ...
>
> </LocationMatch>
>
> It's a bit harder to find in the documentation, but it means this :
> - the <LocationMatch> allows you to match the URI with a regular expression
> "a la perl".  It has the same effect as <Location>, but is a bit more
> flexible as to what you can match.
> - "SetHandler jakarta-servlet" does basically the same as "JkMount", for
> the <Location> in which it is included.
> - SetEnvIf (requires the "mod_setenvif" standard Apache module) allows you
> (between other things) to set/unset variables based on requests
> characteristics (such as here whether the request URI is for one of the file
> extensions indicated).
> - and finally, using this to set the "no-jk" variable has the effect (if
> the URI matches), to *not* re-direct this request through mod_jk.
>
> All of this together means that :
> - if the URI matches /AB, it would normally be re-directed through mod_jk
> and it's load balancer, to the back-end systems
> - but, if the request matches the "SetEnvIf", then the no-jk variable will
> be set
> - thus, when mod_jk receives the request, it will "decline" it (give it
> back to Apache saying "it's not for me")
> - thus Apache will apply to this request any other directives present in
> the same <Location> section (represented here by "...", but which could be
> mod_perl handlers etc..)
>
> Does this give you new ideas ?
>
> (You might also want to look up the "JkUnMount" directive.)
>
> Now, let me comment on the way you phrase your request :
> >> If request comes from URL /AB and content of URL /AB has content in
> >> certain format then ...
> (you would like it to go there, else somewhere else)
>
> There is a bit of a problem here, if taken literally.  The problem is that
> in order to know the format of the content, this content must be generated.
>  To generate it, you have to decide which process will generate it, and let
> it do it.  Then based on the content, you want to decide who generates it.
> A bit of a chicken-and-egg problem here, no ?
> Or by "content" do you just mean the file extension, as it appears in the
> URI ?
>
>
> André
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>  "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Re: Using rewrite to forward the request OR mod_perl

Posted by André Warnier <aw...@ice-sa.com>.
Mohit Anchlia wrote:
[...]

>> We have a web server that redirects traffic to app server using mod_jk load
>> balancer.
>>
>> Now I need to do the following:
>>
>> 1. If request comes from URL /AB and content of URL /AB has content in
>> certain format then forward it to mod_jk otherwise forward it to some other
>> URL (external system in our case).

I may be late with this answer, but for the first part above, you may be 
interested to know that there is an alternative to the "JkMount" 
directives, like this :

<LocationMatch "/AB">
   SetHandler jakarta-servlet
   SetEnvIf REQUEST_URI "\.(htm|web|css|gif|jpg|js|html?)$" no-jk
   ...

</LocationMatch>

It's a bit harder to find in the documentation, but it means this :
- the <LocationMatch> allows you to match the URI with a regular 
expression "a la perl".  It has the same effect as <Location>, but is a 
bit more flexible as to what you can match.
- "SetHandler jakarta-servlet" does basically the same as "JkMount", for 
the <Location> in which it is included.
- SetEnvIf (requires the "mod_setenvif" standard Apache module) allows 
you (between other things) to set/unset variables based on requests 
characteristics (such as here whether the request URI is for one of the 
file extensions indicated).
- and finally, using this to set the "no-jk" variable has the effect (if 
the URI matches), to *not* re-direct this request through mod_jk.

All of this together means that :
- if the URI matches /AB, it would normally be re-directed through 
mod_jk and it's load balancer, to the back-end systems
- but, if the request matches the "SetEnvIf", then the no-jk variable 
will be set
- thus, when mod_jk receives the request, it will "decline" it (give it 
back to Apache saying "it's not for me")
- thus Apache will apply to this request any other directives present in 
the same <Location> section (represented here by "...", but which could 
be mod_perl handlers etc..)

Does this give you new ideas ?

(You might also want to look up the "JkUnMount" directive.)

Now, let me comment on the way you phrase your request :
 >> If request comes from URL /AB and content of URL /AB has content in
 >> certain format then ...
(you would like it to go there, else somewhere else)

There is a bit of a problem here, if taken literally.  The problem is 
that in order to know the format of the content, this content must be 
generated.  To generate it, you have to decide which process will 
generate it, and let it do it.  Then based on the content, you want to 
decide who generates it.
A bit of a chicken-and-egg problem here, no ?
Or by "content" do you just mean the file extension, as it appears in 
the URI ?


André


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org