1

I have an Apache reverse proxy set to move requests to a Tomcat Applet. The config is similar to:

<VirtualHost 100.100.100.100:80>
    ProxyPass /AppName/App http://1.1.1.1/AppName/App
    ProxyPassReverse /AppName/App http://1.1.1.1/AppName/App
</VirtualHost>

I also have a page called summary.html that exists on 1.1.1.1 as:

http://1.1.1.1/AppName/summary.html

When I browse directly to it I have no problem viewing it, however if I try to get there via the reverse proxy I get a blank page. Wireshark shows me a 503, but this one is coming from the Apache reverse proxy (IP 100.100.100.100) and not the Tomcat (IP 1.1.1.1).

Should I add http://1.1.1.1/AppName/ to the config? How? I tried it but I get a blank page, however this one shows on the URL bar of the browser the internal IP of the Tomcat, so, no go.

Help is appreciated.

Thanks.

EDIT: This is the dump from Wireshark:

GET /AppName/ HTTP/1.1
Host: 100.100.100.100
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Cache-Control: max-age=0
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

HTTP/1.1 404 Not Found
Date: Tue, 30 Jan 2012 09:08:51 GMT
Server: Apache
Content-Length: 1
Connection: close
Content-Type: text/html; charset=iso-8859-1
Mr Aleph
  • 231
  • 1
  • 5
  • 10

3 Answers3

1

I suspect you forgot "ProxyPreserveHost On".

Without this directive, your app is contacted with the HTTP "Host: 1.1.1.1" header, while when you were browsing directly it would see "Host: the.domain.com".

zerodeux
  • 656
  • 4
  • 6
0

Adding it like this should work just fine:

<VirtualHost 100.100.100.100:80>
    ProxyPass /AppName/ http://1.1.1.1/AppName/
    ProxyPassReverse /AppName/ http://1.1.1.1/AppName/
</VirtualHost>

Or even:

<VirtualHost 100.100.100.100:80>
    ProxyPass /AppName/summary.html http://1.1.1.1/AppName/summary.html
    ProxyPassReverse /AppName/summary.html http://1.1.1.1/AppName/summary.html
    ProxyPass /AppName/App http://1.1.1.1/AppName/App
    ProxyPassReverse /AppName/App http://1.1.1.1/AppName/App
</VirtualHost>

Can you clarify what issue occurs when you have a config like this in place? I'm not quite sure what you mean by "this one shows on the URL bar of the browser the internal IP of the Tomcat".

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
  • When you browse to `100.100.100.100/AppName/summary,html` it presents a blank page and the URL on the browser gets changed to `1.1.1.1/AppName/summary.html`. – Mr Aleph Jan 30 '12 at 15:43
  • Also, what if I want to do a generic error handling on Tomcat. Ideally every time a 404 or 500 or whatever is thrown I want to show a customized error.html. I have that in place on the config for Tomcat, however with the VirtualHost on Apache it doesn't display the error page either. – Mr Aleph Jan 30 '12 at 15:46
  • @MrAleph Then you need to trace what's actually happening with the request; something's responding with a redirect, but Apache shouldn't allow that `Location` header in a response unmodified with a proper `ProxyPassReverse` config in place. Have you tried with the configs that I've provided? – Shane Madden Jan 30 '12 at 16:10
  • I am doing it as I type. I'll post the reply in a bit. Thanks for the help – Mr Aleph Jan 30 '12 at 16:13
  • Same story. All I get is a blank page. If I go directly to `1.1.1.1` then it's fine. Just as a test I assigned an external IP to `1.1.1.1`. If I go directly to that one as `300.300.300.300/AppName/symmary.html` then it's also fine. The minute I try from the reverse proxy then it doesn't work. So my guess is that the reverse proxy doesn't know where to go get that file. I can hardcode it as you said as `ProxyPass /AppName/summary.html http://1.1.1.1/AppName/summary.html` but that would not work for the error pages or if I want to add more pages – Mr Aleph Jan 30 '12 at 18:25
  • @MrAleph So you're getting the blank page for that resource, even when proxying the entire tree with `ProxyPass /AppName/ http://1.1.1.1/AppName/`? – Shane Madden Jan 30 '12 at 18:37
  • Yes. Not only that, the URL bar on the browser changes to the internal IP, as in `http://1.1.1.1/AppName/` – Mr Aleph Jan 30 '12 at 18:59
  • @MrAleph Then that means your `ProxyPassReverse` isn't catching the redirect header correctly - does the rule in that directive match *exactly* to your `ProxyPass` directive, and to the new URL that your browser is getting? Or else the Tomcat app is redirecting with an html refresh element.. can you examine the request with Wireshark or your browser's dev tools to figure out how the redirect is occurring? Also try setting `ProxyPreserveHost On`; that may fool the screwed up redirect that the Tomcat app is sending. – Shane Madden Jan 30 '12 at 19:06
  • I tried that but I can't make anything out of what Wireshark says. I added a dump to the question. – Mr Aleph Jan 31 '12 at 15:14
0

I would use a rewrite rule instead.

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule

try:

<VirtualHost 100.100.100.100:80>
    RewriteRule ^/AppName/(.*) http://1.1.1.1/AppName$1 [P]
</VirtualHost>
Sam
  • 617
  • 1
  • 6
  • 14