3

I'm trying to use an Apache proxy as a front-end for a service running on a different server in my infrastructure. Let's call them proxy.example.com and service.example.com.

Proxy.example.com is listening on port 80, but service.example.com is listening on port 8888. The first thing that service.example.com does when you connect to it is to send a 302 redirect which has port 8888 included in it -- and Apache is correctly remapping the domain name but not the port in the redirect. The service on service.example.com is a third-party packaged product, so let's assume that we can't change the way it works in any way.

The relevant bit of Apache config looks like this:

ProxyPreserveHost On
ProxyPass / http://service.example.com:8888/
ProxyPassReverse / http://service.example.com:8888/

Here are some (lightly anonymised) telnets to port 80. First, going direct to service.example.com:

$ telnet service.example.com 8888
Trying xxx.xxx.xxx.xxx...
Connected to service.example.com.
Escape character is '^]'.
GET / HTTP/1.0
Host: service.example.com

HTTP/1.0 302 Found
Date: Thu, 19 Jan 2012 10:38:54 GMT
Content-Type: text/html
Location: http://service.example.com:8888/directory/index.html

Connection closed by foreign host.

And going via proxy.example.com:

$ telnet proxy.example.com 80
Trying yyy.yyy.yyy.yyy... 
Connected to proxy.example.com.
Escape character is '^]'.
GET / HTTP/1.0
Host: proxy.example.com

HTTP/1.1 302 Found
Date: Thu, 19 Jan 2012 10:41:08 GMT
Location: http://proxy.example.com:8888/directory/index.html
Via: 1.0 service.example.com
Vary: Accept-Encoding
Content-Length: 0
Connection: close

Connection closed by foreign host.

So, how can I make Apache remap the port number as well as the domain name in the 302 redirect?

1
  • This specific issue can be fixed with a rewrite from / to proxy.example.com/directory/index.html -- getting the Apache proxy to do the redirect rather than the service. But it would still be good to have an answer to the generic case.
    – Mike Scott
    Jan 19, 2012 at 11:30

1 Answer 1

3

I am just guessing here, but as far as I can tell, ProxyPreserveHost is not needed here. I have backend services on non standard ports (>9000) and it is working as expected with just ProxyPass and ProxyPassRevere directives

Could you try again after commenting out ProxyPreserveHost On ?

1
  • 2
    To clarify, the reason that this worked is that the service server doesn't care what Host header is sent. It was simply echoing back the Host that it received for the Location header, but appending what it thought to be the proper port. Now that ProxyPreserveHost is off, it's catching the ProxyPassReverse, so an alternate fix (in case your service were host-header sensitive) would be to add ProxyPassReverse / http://proxy.example.com:8888/ in addition to your existing ProxyPassReverse. Jan 19, 2012 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.