We've been using NGINX for a while, partly as a load-balancer. Today I've been learning lots about NGINX configuration.
The problem? We're migrating our service from an old server farm to a new server farm, but it's going to take a few days to port the data. To avoid a service outage we wanted to modify our NGINX front end to do the following:
PUTs and POSTs go to the new server farm.
GETs go the the new server farm first, if they get a 404 they try the old server farm.
DELETEs go to both the new and old server farms.
My solution looks like this:
upstream old_servers {
server 192.168.0.1:80;
server 192.168.0.2:80;
}
upstream new_servers {
server 192.168.1.1:80;
server 192.168.1.2:80;
}
server{
listen 80 default_server;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /service/docs {
proxy_intercept_errors on;
error_page 404 = @old;
post_action @replicate;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://new_servers;
}
location @replicate {
proxy_set_header X-Real-IP $remote_addr;
if ($request_method = DELETE) {
proxy_pass http://old_servers;
}
}
location @old {
proxy_set_header X-Real-IP $remote_addr;
if ($request_method = GET) {
proxy_pass http://old_servers;
}
}
}
It seems to work, but is there a better way?
Andy Miller
Crocodile RCS ltd.