Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 '12 at 11:30

1 Answer 1

up vote 2 down vote accepted

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 ?

share|improve this answer
    
Perfect -- thank you. –  Mike Scott Jan 19 '12 at 13:08
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. –  Shane Madden Jan 19 '12 at 17:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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