The Apache documentation pretty clearly states that mod_rewrite
should only be a last resort. For nginx
, the Pitfalls section has examples where the request_uri
is essentially unchanged.
The situation is this:
- We (a department in an institute) have a main webserver which is due to be upgraded soon (running Debian 6). To deal with the upgrade, I have set up an nginx server, which will proxy parts known to be working fine to an upgraded server and others to the old server.
- The old server had a number of
ProxyPass
rules (a significant amount of its work is proxying). I wish to shift all of them tonginx
, since, as I understand,nginx
is more performant in proxying. - A large number of users have user home directories being served by another server. For these users, but tilde and non-tilde versions are available (i.e.,
http://my.site/muru
andhttp://my.site/~muru
would be proxied tohttp://other.server/~muru
, buthttp://other.server/muru
doesn't exist). - A number of folders were proxied to a different folder on the same server. (e.g.,
http://my.site/local-club
would be proxied tohttp://my.site/~local-club
).
My main question is:
- Given A and B both being proxied to C on a different server, should I use
rewrite
orlocation
withreturn
to redirect requests forB
toA
, or continue proxying both? - Given A and B both on the same server, with B being proxied to A, should I use rewrites or returns to redirect B to A?
Redirection (and return
) has the benefit of clearly indicating the relation between the two directories.
My rewrite
rules look like:
rewrite ^/B(/.*) /A$1 permanent;
And the return
rules:
location ~ ^/B(/.*) {
return 301 /A$1;
}
With:
location ~ ^/~(A|D|E|F..)/ {
proxy_pass https://other.server;
proxy_redirect default;
}