I’m new to NGINX and I am migrating a server. I haven’t finished everything on the new server, so I want it to match to the new server, unless that resource or path doesn’t exist. If so, I want to send it to the old server. Is there way to do that?
Asked
Active
Viewed 1.4k times
1 Answers
17
I did this by a hack with proxy_next_upstream
Define a upstream, forward most of reqeusts to new_server by controlling the weight, proxy_next_upstream
will retry to forward the failed request to next server (old_server)
upstream backend {
server new_server weight=10000;
server old_server weight=1;
}
server {
location / {
proxy_pass http://backend;
proxy_next_upstream error timeout http_404 http_500 http_502 http_503 http_504 non_idempotent;
}
}
===========
Solution II
server {
location / {
proxy_pass http://new_server;
error_page 404 500 502 503 504 = @fallback;
}
location @fallback {
proxy_pass http://old_server;
}
}

Larry.He
- 604
- 5
- 16