You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ron Van den Branden <ro...@kantl.be> on 2012/03/29 14:39:02 UTC

[users@httpd] mod_proxy: ProxyPreserveHost omits start of proxied path

Hi,

I am setting up a reverse proxy configuration that will proxy all 
requests starting with /apps/ to a Tomcat server running on a closed 
port. I have set up following configuration in httpd.conf:

   ProxyRequests	off
   ProxyPass/apps/     http://localhost:8082/
   ProxyPassReverse/apps/http://localhost:8082/
   ProxyPassReverseCookiePath/apps/  /

This generally works, even for internal redirections inside the Tomcat 
apps I'm addressing. Suppose my Tomcat app is internally accessible at 
<http://localhost:8082/my_app/>, and this request is internally 
redirected to <http://localhost:8082/my_app/index.htm>, a request for 
<http://mydomain/apps/my_app/> is correctly redirected to 
<http://mydomain/apps/my_app/index.htm>.

Yet, there's a webstart application inside a Tomcat app that needs the 
*original* URL, instead of the proxied 'localhost:8082' URL. Hence, I 
tried by adding:

   ProxyPreserveHost	on

But this does not work 100%:
     -internal redirects inside the Tomcat app omit the /apps/ part from 
the redirected URL. For example, a request for 
<http://mydomain/apps/my_app/> now ends up at 
<http://mydomain/my_app/index.htm>.
     -also (and probably related): the webstart application inside the 
Tomcat app doesn't preserve the /app/ part of the original request, and 
fails.

All does work perfectly, however, with ProxyPreserveHost switched on, 
when the entire URL space is proxied: "ProxyPass     /    
http://localhost:8082/" etc. But I explicitly want to limit the proxying 
to just one URL pattern, starting with '/apps/'. How can the '/apps/' 
part of the original request be passed on to the proxied URL (as 
apparently was the case with ProxyPreserveHost switched off)? (Note: 
proxying to http://localhost:8082/apps/ is not an option, as there is no 
physical /apps/ folder there).

I hope this sketches my problem.  I have the feeling I'm almost there; 
any help much appreciated!

Ron

Re: [users@httpd] mod_proxy: ProxyPreserveHost omits start of proxied path

Posted by Ron Van den Branden <ro...@kantl.be>.
Hi,

On 30/03/2012 12:39, Tom Evans wrote:
> On Fri, Mar 30, 2012 at 11:14 AM, Bruno Tréguier<Br...@shom.fr>  wrote:
>> Would it be possible for you to do new captures of the network traffic, but
>> in "pcap" format ? That way we could use tools like wireshark to analyse the
>> traces, instead of the ascii dump you provided, whih (in my opinion) is
>> difficult to read.
> I'm looking at preserveHostOn_redirect.out. If you look at the section
> "08:54:11.860428 … localhost.8082>  localhost.34050" , this is the
> backend replying to Apache (afaict).
>

Thanks a lot, guys, for your kind and patient help! Sorry about my 
(tcp)dumbness, and many thanks, Tom, for diving straight into that ascii 
soup.

> You should be using something like this:
>
>    ProxyPassReverse /apps/ http://ctb.dev.kantl.be/
>
> as that is the URI structure your backend is generating.

Ok, this makes sense (to our server, too). This fixes the issue with 
redirections by the proxied app, great!

Yet, there's one scenario that's still slipping between the mazes, which 
unfortunately seems to fall between both Apache and the proxied webapp 
(serving the eXist XML database (http://exist-db.org) via Tomcat). The 
proxied webapp provides a Java webstart client that allows for remote 
access to the XML database. Yet, using these proxy settings:

   ProxyRequests	    off
   ProxyPreserveHost on

   ProxyPass /apps/      http://localhost:8082/
   ProxyPassReverse /apps/    http://ctb.dev.kantl.be/
   ProxyPassReverseCookiePath /apps/ /

Requests for the webstart client 
(http://ctb.dev.kantl.be/apps/TW/webstart/exist.jnlp) fail on the 
backend side. Though the original proxied request lands at the right 
place, I guess the Java webstart file makes further requests to the 
wrong URL. Looking at the logs, the backend side apparently sees this 
URL: http://ctb.dev.kantl.be/TW/webstart/exist.jnlp, instead of the 
original one with the '/apps/' path part. I've checked this further via 
a function of the proxied eXist webapp: request:get-url(), which returns 
the URL of the current request. Apparently, when calling that function 
for http://ctb.dev.kantl.be/apps/TW/eXide/, following URL is returned: 
http://ctb.dev.kantl.be/TW/eXide/, hence without the '/apps/' part.

The problem seems to be that I want the '/apps/' part in the request in 
order to limit proxying behaviour to requests starting with that part. 
Yet, that '/apps/' part is not part of a physical path in the proxied 
app folder structure, and hence needs to be filtered out in the proxied 
request (which is what ProxyPass and ProxyPassReverse do, IIUC). Yet, 
some parts of that app need access to the original URL, including that 
'/apps/' part. Is there a way to pass on the '/apps/' part of the 
original request to the proxied app, or is this outside of Apache's reach?

Sorry about the muddiness; I hope to have made myself clear.

Kind regards,

Ron

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_proxy: ProxyPreserveHost omits start of proxied path

Posted by Tom Evans <te...@googlemail.com>.
On Fri, Mar 30, 2012 at 11:14 AM, Bruno Tréguier <Br...@shom.fr> wrote:
> Ron,
>
> Would it be possible for you to do new captures of the network traffic, but
> in "pcap" format ? That way we could use tools like wireshark to analyse the
> traces, instead of the ascii dump you provided, whih (in my opinion) is
> difficult to read.
>
> You can use the tcpdump "-w file.pcap" option for that (add it to the other
> ones).
>
> Thanks !
>
> Bruno

With "-s 0" as well would be perfect, otherwise the packets are
truncated a little short to be useful!

I'm looking at preserveHostOn_redirect.out. If you look at the section
"08:54:11.860428 … localhost.8082 > localhost.34050" , this is the
backend replying to Apache (afaict).

The "Location" header has this value:

    0x0070:  6f63 6174 696f 6e3a 2068 7474 703a 2f2f  ocation:.http://
    0x0080:  6374 622e 6465 762e 6b61 6e74 6c2e 6265  ctb.dev.kantl.be
    0x0090:  2f54 572f 6558 6964 652f 696e 6465 782e  /TW/eXide/index.
    0x00a0:  6874 6d6c 0d0a 436f 6e74 656e 742d 4c65  html..Content-Le

IE "(L)ocation: http://ctb.dev.kantl.be/TW/eXide/index.html"

IIRC your proxy settings are:

  ProxyRequests	on
  ProxyPass            /apps/    http://localhost:8082/
  ProxyPassReverse    /apps/    http://localhost:8082/
  ProxyPassReverseCookiePath /apps/ /

"http://ctb.dev.kantl.be/TW/eXide/index.html" does not start with
"http://localhost:8082/", so Apache does not rewrite the location
header. You should be using something like this:

  ProxyPassReverse /apps/ http://ctb.dev.kantl.be/

as that is the URI structure your backend is generating. In the
example dump, this would have rewritten the Location header to
"/apps/TW/eXide/index.html", which Apache would then turn into a
canonical URL, as per your UseCanonicalName settings.

Note that you can have as many ProxyPassReverse directives as you
need, if different parts of the backend generate different URIs.

Cheers

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_proxy: ProxyPreserveHost omits start of proxied path

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 30/03/2012 12:05, ron.vandenbranden@home a écrit :
>   Hi,
>
> On 30/03/2012 11:01, Igor Cicimov wrote:
>>
>> Have you actually read the mod_proxy documentation or you are just
>> working with some example you found somewhere? If you read it you will
>> find that you can use ! in the ProxyPass to exclude a path from the proxy.
>>
>
> Of course I have, but I don't think that's the issue: i do want to
> reverse proxy requests starting with /apps/. All works fine without
> ProxyPreserveHost:

Ron,

Would it be possible for you to do new captures of the network traffic, 
but in "pcap" format ? That way we could use tools like wireshark to 
analyse the traces, instead of the ascii dump you provided, whih (in my 
opinion) is difficult to read.

You can use the tcpdump "-w file.pcap" option for that (add it to the 
other ones).

Thanks !

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_proxy: ProxyPreserveHost omits start of proxied path

Posted by "ron.vandenbranden@home" <ro...@kantl.be>.
Hi,

On 30/03/2012 11:01, Igor Cicimov wrote:
>
> Have you actually read the mod_proxy documentation or you are just 
> working with some example you found somewhere? If you read it you will 
> find that you can use ! in the ProxyPass to exclude a path from the proxy.
>

Of course I have, but I don't think that's the issue: i do want to 
reverse proxy requests starting with /apps/. All works fine without 
ProxyPreserveHost:

>        ProxyRequests	off
>        ProxyPass//apps//     http://localhost:8082/  <http://localhost:8080/>
>        ProxyPassReverse///apps/http://localhost:8082/  <http://localhost:8080/>
>        ProxyPassReverseCookiePath//apps//  /
>

Yet, switching ProxyPreserveHost on seems to make ProxyPassReverse to be 
ignored. Internal redirects end up without the /apps/ part, while it 
should be preserved. With ProxyPreserveHost, it's as if above 
ProxyPassReverse instructive is always interpreted as:

   ProxyPassReverse///     http://localhost:8082/  <http://localhost:8080/>

...no matter what actual value is given in the first argument: all 
internal redirects inside the proxied app end up at the wrong path, 
e.g.: <http://mydomain/my_app/index.htm> instead of 
<http://mydomain/apps/my_app/index.htm>.

Unfortunately, some part of the proxied app needs access to the original 
host (http://mydomain/), instead of the proxied host 
(http://localhost:8082). That's what I understood ProxyPreserveHost was 
for, but it doesn't work completely as I'd expect, given the ProxyPass 
directive, and I don't see what causes this difference.

I want to seriously investigate and fix this issue and really appreciate 
your help. However, I'll be off-line for the next week, but will 
investigate further when I'm back from holiday.

Kind regards,

Ron

Re: [users@httpd] mod_proxy: ProxyPreserveHost omits start of proxied path

Posted by Igor Cicimov <ic...@gmail.com>.
Have you actually read the mod_proxy documentation or you are just working
with some example you found somewhere? If you read it you will find that
you can use ! in the ProxyPass to exclude a path from the proxy.
 On Mar 29, 2012 11:39 PM, "Ron Van den Branden" <ro...@kantl.be>
wrote:

>  Hi,
>
> I am setting up a reverse proxy configuration that will proxy all requests
> starting with /apps/ to a Tomcat server running on a closed port. I have
> set up following configuration in httpd.conf:
>
>   ProxyRequests	off
>   ProxyPass            */apps/*    http://localhost:8082/ <http://localhost:8080/>
>   ProxyPassReverse    */*apps/    http://localhost:8082/ <http://localhost:8080/>
>   ProxyPassReverseCookiePath */apps/* /
>
> This generally works, even for internal redirections inside the Tomcat
> apps I'm addressing. Suppose my Tomcat app is internally accessible at
> <http://localhost:8082/my_app/> <http://localhost:8082/my_app/>, and this
> request is internally redirected to
> <http://localhost:8082/my_app/index.htm><http://localhost:8082/my_app/index.htm>,
> a request for  <http://mydomain/apps/my_app/><http://mydomain/apps/my_app/>is correctly redirected to
> <http://mydomain/apps/my_app/index.htm><http://mydomain/apps/my_app/index.htm>
> .
>
> Yet, there's a webstart application inside a Tomcat app that needs the
> *original* URL, instead of the proxied 'localhost:8082' URL. Hence, I tried
> by adding:
>
>   ProxyPreserveHost	on
>
> But this does not work 100%:
>     -internal redirects inside the Tomcat app omit the /apps/ part from
> the redirected URL. For example, a request for
> <http://mydomain/apps/my_app/> <http://mydomain/apps/my_app/> now ends up
> at <http://mydomain/my_app/index.htm> <http://mydomain/my_app/index.htm>.
>     -also (and probably related): the webstart application inside the
> Tomcat app doesn't preserve the /app/ part of the original request, and
> fails.
>
> All does work perfectly, however, with ProxyPreserveHost switched on, when
> the entire URL space is proxied: "ProxyPass     /
> http://localhost:8082/" etc. But I explicitly want to limit the proxying
> to just one URL pattern, starting with '/apps/'. How can the '/apps/' part
> of the original request be passed on to the proxied URL (as apparently was
> the case with ProxyPreserveHost switched off)? (Note: proxying to
> http://localhost:8082/apps/ is not an option, as there is no physical
> /apps/ folder there).
>
> I hope this sketches my problem.  I have the feeling I'm almost there; any
> help much appreciated!
>
> Ron
>