nginx / wp : change 302 location

I know this is a recurring question but I did not find any working solution.

I would like to have the same wordpress (i.e. same directory / same config / same database) working on 2 different addresses.
let say that this two addresses are A.exemple.com:81 and B.exemple.com:81, while the wordpress database is configured to work with the generic address www.exemple.com. (changing database configuration cannot help ;o( )

Read More

I am working with two Nginx servers, configured to work in fastcgi mode.

In “A.exemple.com” nginx configuration file,
I make wordpress believe it works on the good host :

fastcgi_param   HTTP_HOST       "www.exemple.com";
fastcgi_param   SERVER_NAME     "www.exemple.com";
fastcgi_param   SERVER_PORT     "80";

(those parameter are under comment in default fastcgi_param… )

I modifie generated html to keep browser in the right subdomain

sub_filter_types text/css text/xml;
sub_filter_once off;
sub_filter "www.exemple.com" "A.exemple.com:81";

and everything is ok ;o)

now, the trouble…
when logging on admin panel is a success, wordpress sends a 302 response with location

www.exemple.com/wp-admin/

and, of course, I need to change this location too

A.exemple.com:81/wp-admin/

I’ve tried several things without success :

#add this in location 
proxy_redirect http://www.exemple.com/ http://A.exemple.com:81/ ;

or

#add this in location 
fastcgi_intercept_errors on;
error_page 302 =[what you want] @fallback;
and 
location @fallback {
    proxy_redirect http://www.exemple.com/ http://A.exemple.com:81/ ;
}

but nothing works. May the fact that I use fastcgi have anything to do with it ?
any help is welcome

thanks !!

Related posts