You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by André Warnier <aw...@ice-sa.com> on 2009/01/01 13:47:04 UTC

[users@httpd] convert from mod_jk to proxy_ajp

Hi.

I am running into trouble when trying to change the configuration of an 
existing Apache2.2.3/Tomcat5.0  combination (on the same host), and 
replacing the current mod_jk connector by mod_proxy_ajp.
I have never used mod_proxy before.

This is the original configuration which works, using mod_rewrite and 
mod_jk, (lines numbered (n) for easy reference only ) :

<VirtualHost *:80>
....
DocumentRoot /srv/www/star1/docs
...
RewriteCond %{REQUEST_URI} !/servlet\.[^\.]+$      (1)
RewriteRule ^/xyz/(.*)$ /$1 [PT]               (2)
SetEnvIf REQUEST_URI "\.(htm|web|css|gif|jpg|js|html?)$" no-jk    (3)
<LocationMatch "/servlet\.[^.]+$">   (4)
   SetHandler jakarta-servlet  (5)
</LocationMatch>
...
</VirtualHost>

Expplanation :
URIs that need to be redirected to a "xyz" webapp under Tomcat all end 
in "servlet.xxxxxx?" and start with "/xyz/".
Some URIs that start with /xyz/ are for static items, that I prefer to 
serve with Apache. But in such a case, I have to remove the /xyz/ prefix 
prior to serving the item.
So what is done above is :
(1) and (2) : for URI's which start with /xyz/ but are *not* for the 
webapp, remove the /xyz/ prefix and serve the result locally.
(3) for URIs that represent static items, also set the "no-jk" flag.
(4) and (5) redirect all URI's ending in "/servlet.xxxx" to Tomcat

There is a bit of overlap between some of the above, but it works fine.

Now I try to replace the above with a configuration using mod_proxy and 
mod_proy_ajp, as follows :

<VirtualHost *:80>
....
DocumentRoot /srv/www/star1/docs
...
ProxyRequests Off
<Proxy *>
   Order Allow,Deny
   Allow from all
</Proxy>
RewriteCond %{REQUEST_URI} !/servlet\.[^\.]+$
RewriteRule ^/xyz/(.*)$ /$1 [PT]
<LocationMatch "/servlet\.[^.]+$">
   ProxyPass ajp://localhost:8009
</LocationMatch>
...
</VirtualHost>

I am hoping with the above to make it so that a URI like
URI = "/xyz/....../servlet.myservlet?...."
will
a) not be touched by the RewriteRule (like before)
b) forwarded to Tomcat via mod_prox_ajp as
ajp://localhost:8009/xyz/....../servlet.myservlet?....

but I am getting "File not found" errors (from Apache) when trying to 
access links involving the servlet.
Like :
File "/srv/www/star1/docs/xyz/" not found.

This is true, the directory "/srv/www/star1/docs/xyz/" does not exist 
under the Apache document root.  But this URI should be re-directed to 
Tomcat, and it does not seem to be. So, what am I doing wrong ?

Thanks in advance.

---------------------------------------------------------------------
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] convert from mod_jk to proxy_ajp

Posted by André Warnier <aw...@ice-sa.com>.
André Warnier wrote:
>>
> 
> (*) For example, could I spare the <LocationMatch> and ProxyPass 
> entirely, and use a RewriteRule to forward this directy to the ajp port, 
> a bit like :
> RewriteRule ^/(xyz/.*/servlet\.[^\.]+)$ ajp://localhost:8009/$1 [PT]
> ?
> 
Replying to my own post here. Sorry, I went back to the doc, and that 
seems to be what [P] (instead of [PT]) is all about. So I guess it does 
work, but also it does not allow me to use the convenience of a 
<Location> section to do other things to these requests (like an output 
filter).


---------------------------------------------------------------------
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] convert from mod_jk to proxy_ajp

Posted by André Warnier <aw...@ice-sa.com>.
Eric Covener wrote:
> On Thu, Jan 1, 2009 at 7:47 AM, André Warnier <aw...@ice-sa.com> wrote:
>> RewriteCond %{REQUEST_URI} !/servlet\.[^\.]+$
>> RewriteRule ^/xyz/(.*)$ /$1 [PT]
>> <LocationMatch "/servlet\.[^.]+$">
>>  ProxyPass ajp://localhost:8009
>> </LocationMatch>
> 
>> File "/srv/www/star1/docs/xyz/" not found.
> 
> Are there any other rewrites that actually apply to the servlet and
> don't use PT?  

Not in this case, no.

A matching RewriteRule w/o PT will prevent parts of
> mod_proxy from running (where it tags a request as being for the
> proxy, to be handled later)
> 
> My usual suggestion/simplification is to use rewrite with the P flag
> whenever rewrite and proxy are required for the same context root. 

As mentioned in my post, I am new to this, and not quite clear yet about 
the interaction between mod_rewrite and mod_proxy. (*)

Another point a bit obscure to me is when using the <LocationMatch> 
section above, if the ProxyPass then really works as expected, taking 
the complete matching URI as argument 1.
Apparently the ProxyPass does not work, because Apache is trying to 
server the URI itself.  But if I try to add an URI first argument to 
ProxyPass, it signals an error in the arguments at startup of Apache.

  I
> believe in 2.0.x it was less predictable because the Proxy could
> actually run first and prevent rewrite from happening at all.

The Apache version is 2.2.3 here, so it should not be a concern.

> 
> If you're handy with a debugger, 
not at all

"proxy_trans" is the name of the
> function that can be "covered up".
> 

(*) For example, could I spare the <LocationMatch> and ProxyPass 
entirely, and use a RewriteRule to forward this directy to the ajp port, 
a bit like :
RewriteRule ^/(xyz/.*/servlet\.[^\.]+)$ ajp://localhost:8009/$1 [PT]
?

I am not quite sure that I really want to do this, because the 
<LocationMatch> section is also handy to add other things, so let's say 
this is just curiosity at this point.


Thanks.

---------------------------------------------------------------------
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] convert from mod_jk to proxy_ajp

Posted by Eric Covener <co...@gmail.com>.
On Thu, Jan 1, 2009 at 7:47 AM, André Warnier <aw...@ice-sa.com> wrote:
> RewriteCond %{REQUEST_URI} !/servlet\.[^\.]+$
> RewriteRule ^/xyz/(.*)$ /$1 [PT]
> <LocationMatch "/servlet\.[^.]+$">
>  ProxyPass ajp://localhost:8009
> </LocationMatch>

>File "/srv/www/star1/docs/xyz/" not found.

Are there any other rewrites that actually apply to the servlet and
don't use PT?  A matching RewriteRule w/o PT will prevent parts of
mod_proxy from running (where it tags a request as being for the
proxy, to be handled later)

My usual suggestion/simplification is to use rewrite with the P flag
whenever rewrite and proxy are required for the same context root.  I
believe in 2.0.x it was less predictable because the Proxy could
actually run first and prevent rewrite from happening at all.

If you're handy with a debugger, "proxy_trans" is the name of the
function that can be "covered up".

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
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