Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 and is listening on port 80, but is listening on port 8888. The first thing that 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 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 /
ProxyPassReverse /

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

$ telnet 8888
Connected to
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.0 302 Found
Date: Thu, 19 Jan 2012 10:38:54 GMT
Content-Type: text/html

Connection closed by foreign host.

And going via

$ telnet 80
Trying yyy.yyy.yyy.yyy... 
Connected to
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 302 Found
Date: Thu, 19 Jan 2012 10:41:08 GMT
Via: 1.0
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 -- 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
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
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 / in addition to your existing ProxyPassReverse. – Shane Madden Jan 19 '12 at 17:47

Your Answer


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.