24

I am running a WebApplication on a Servlet Container (port 8080) in an environment that can be accessed from the internet (external) and from company inside (intenal), e.g.

http://external.foo.bar/MyApplication
http://internal.foo.bar/MyApplication

The incomming (external/internal) requests are redirected to the servlet container using an apache http server with mod_proxy. The configuration looks like this:

ProxyPass /MyApplication http://localhost:8080/MyApplication retry=1 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse /MyApplication http://localhost:8080/MyApplication

I am now facing the problem that some MyApplication responses depend on the original request URL. Concrete: a WSDL document will be provided with a element that has a schemaLocation="<RequestUrl>?xsd=MyApplication.xsd" element.

With my current configuration it always looks like

<xs:import namespace="..." schemaLocation="http://localhost:8080/MyApplication?xsd=MyApplication.xsd"/>

but it should be

External Request: <xs:import namespace="..." schemaLocation="http://external.foo.bar/MyApplication?xsd=MyApplication.xsd"/>
Internal Request: <xs:import namespace="..." schemaLocation="http://internal.foo.bar/MyApplication?xsd=MyApplication.xsd"/>

I suppose this is a common requirement. But as I am no expert in configuration of the apache http server and its modules I would be glad if someone could give some (detailed) help.

Thanks in advance!

FrVaBe
  • 47,963
  • 16
  • 124
  • 157

3 Answers3

28

If you're running Apache >= 2.0.31 then you might try to set the ProxyPreserveHost directive as described here.

This should pass the original Host header trough mod_proxy into your application, and normally the request URL will be rebuild there (in your Servlet container) using the Host header, so the schema location should be build using the host and path infos from "before" the proxy.

(Posted here too for the sake of completeness)

gawi
  • 2,843
  • 4
  • 29
  • 44
jCoder
  • 2,289
  • 23
  • 22
7

Here is another alternative if you would like to retain both the original host name and the proxied host name.

If you are using mod_proxy disable ProxyPreserveHost in the Apache configuration. For most proxy servers, including mod_proxy, read the X-Forwarded-Host header in your application. This identifies the original Host header provided by the HTTP request.

You can read about the headers mod_proxy (and possible other standard proxy servers) set here:

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

ricosrealm
  • 1,616
  • 1
  • 16
  • 26
  • `ProxyPreserveHost` worked perfect for me without the need to change my application (read the X-Forwarded-Host). But nevertheless thanks for this possible other solution. – FrVaBe Apr 30 '13 at 07:25
  • 2
    Yup. It worked for me as well. However I ran into a case where I needed both the original host name and the proxy-passed host name. So just adding this here for future reference. – ricosrealm Apr 30 '13 at 08:52
1

You should be able to do a mod_rewrite in apache to encode the full URL as a query parameter, or perhaps part of the fragment. How easy this might be depends on whether you might use one or the other as part of your incoming queries.

For example, http://external.foo.bar/MyApplication might get rewritten to http://external.foo.bar/MyApplication#rewritemagic=http://external.foo.bar/MyApplication which then gets passed into the ProxyPass and then stripped out.

A bit of a hack, yes, and perhaps a little tricky to get rewrite and proxy to work in the right order and not interfere with each other, but it seems like it should work.

Seth Robertson
  • 30,608
  • 7
  • 64
  • 57
  • Thanks for working on my problem and +1 for a possible solution approach. But MyApplication is build upon the [Apache CXF](http://cxf.apache.org/) framework and I doubt that a query parameter will help. I think I have to access it with the original request and I wonder if/how this is possible in my scenario. – FrVaBe May 21 '11 at 04:33
  • @K. Claszen: I would suggest dumping all environment, variables, headers, and other information which apache makes available to you to see if something might have been injected. Also, consider if you can use ProxyPreserveHost or ProxyVia (Via is an example of one of those headers that might be set and useful to you). – Seth Robertson May 21 '11 at 19:55
  • I will first try the ProxyPreserverHost setting that I got on [serverfault](http://serverfault.com/questions/272041/retain-original-request-url-on-mod-proxy-redirect/272071#272071). If that will solve my problem it would be very simple... Nevertheless thanks for your support! – FrVaBe May 21 '11 at 20:07