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 have two proxypass rules on my web host, one that points to a local varnish instance for caching purposes, which I want ProxyPreserveHost enabled for, and another that points to a third party hosted site, which I want ProxyPreserveHost disabled for. Is there anyway I can do this on a per rule/pass basis?

share|improve this question

3 Answers 3

Under Apache 2.2, no - the ProxyPreserveHost directive is only valid in the server config or virtual host contexts; you'd need the different ProxyPass statements to be in different virtual hosts.

In Apache 2.4, yes - the directory context has been added for the directive, so you can now do something such as:

<Location /to-varnish/>
    ProxyPreserveHost On
    ProxyPass http://127.0.0.1:8000/to-varnish/
</Location>
<Location /to-third-party/>
    ProxyPreserveHost Off
    ProxyPass http://third-party-site.com/
</Location>
share|improve this answer
    
ah, that makes sense. thanks. –  580farm Dec 4 '12 at 22:09

You can with help of RequestHeader

ProxyPreserveHost On
<LocationMatch third-party-pattern>
   RequestHeader  set  Host  third-party-vhost-name
   ProxyPassMatch  http://third-party-server
</LocationMatch>
<LocationMatch varnish-pattern>
   ProxyPassMatch  http://varnish-server
</LocationMatch>
share|improve this answer

I'm unable to upvote Sorin's response...

In our local situation running Apache 2.2, and the primary app requires proxypreservehost (CQ/AEM author) to login, but a partner we proxy to requires their host in the host header.

We don't need to do this with regex though, a regular <Location...> works fine.

From documentation (http://httpd.apache.org/docs/2.2/mod/core.html#location):

The directive limits the scope of the enclosed directives by URL.

This solution works for us:

  <Location /[path]/ >
    RequestHeader set Host [thirdparty]
  </Location>
  RewriteRule ^/[path]/(.*) https://[thirdparty]/$1 [P,NC,L]

This sets the host header for this request to the partner's hostname.

With that in place, we can continue to login to CQ/AEM author AND proxy to the partner service using their expected host header.

share|improve this answer

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.