0

i have two domain

Domain A : www.fakedomain.com , this is the domain in the client, the idea is just proxy to mainblog when the url is http://www.fakedomain.com/blog

Domain B : www.mainblog.com ,this is to have a multisite wordpress bloga.mainblog.com, blogb.mainblog.com etc

Im trying to proxy a Domain A, to a Domain B, but i want to keep the original hostname (needed by wordpress) , the Proxy works fine but in php $_SERVER['HTTP_HOST'] show me the domain B (maindomain.com) instead of "fakedomain.com",

I read that the solution is to add ProxyPreserveHost On , but in the instant i add it, the site keep looping until Google Chrome breaks,

I though maybe was caused by Wordpress, so i removed all the files, and i have only a index.php with in the mainblog.com , but still looping

<VirtualHost *:80>
    DocumentRoot "d:/www/wp-multisite"
    ServerName mainblog.com
    ServerAlias *.mainblog.com 
    ErrorLog  "logs/wpmultisite-error.log"
    CustomLog "logs/wpmultisite-access.log" common

</VirtualHost>

<VirtualHost *:80>
    ServerName www.fakedomain.com

    <IfModule mod_proxy.c>
        ProxyRequests Off
        ProxyPreserveHost   On
        ProxyPass         /     http://fake.mainblog.com/
        ProxyPassReverse  /     http://fake.mainblog.com/
    </IfModule>

    ErrorLog  "logs/fake-blog-error.log"
    CustomLog "logs/fake-blog-access.log" common
</VirtualHost>
Joyal
  • 101
  • 1
  • 6
  • Are you telling mod_proxy to preserve the Host header while the request will be proxied to the same server? – lsmooth May 23 '13 at 18:18
  • Yeap, is on the same server, but i want to keep is the host name, no care to much of the IP Address , – Joyal May 24 '13 at 07:46

1 Answers1

0

Apache also uses the Host header to identify which VirtualHost to use. By telling mod_proxy to preserve the Host header apache will always serve the request using the second VirtualHost. This is the loop you are seeing. To solve this you'd need to make sure that proxied requests are not served using the second VirtualHost although the Host header is www.fakedomain.com.A way to do this would be to add a VirtualHost like this on the top of your configuration:

<VirtualHost 127.0.0.1:80>
    DocumentRoot "d:/www/wp-multisite"
    ServerName www.fakedomain.com
    ServerAlias *.mainblog.com 
    ErrorLog  "logs/wpmultisite-error.log"
    CustomLog "logs/wpmultisite-access.log" common
</VirtualHost>

Then use the hosts file to make sure fake.mainblog.com resolves to 127.0.0.1 on this server. Both together would ensure that mod_proxy uses 127.0.0.1 as backend while keeping the host header and 127.0.0.1 with Host: www.fakedomain.com would result in the above VirtualHost being used to serve the requests of mod_proxy.

lsmooth
  • 1,541
  • 1
  • 9
  • 18