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?
To find a location match for an URI, NGINX first scans the locations that is defined using the prefix strings (without regular expression). Thereafter, the location with regular expressions are checked in order of their declaration in the configuration file.
By default, the configuration file is named nginx. conf and placed in the directory /usr/local/nginx/conf , /etc/nginx , or /usr/local/etc/nginx .
The nginx location directive is used to tell the nginx where to look for the resources including folders and files, at the time of matching URI against the block. Location directive block will be placed inside into the block of the server or inside into another block.
By default, NGINX webroot is located at /var/www/html.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With