0

I set up two upstream servers as failover in my nginx

upstream backend {
  server 10.0.0.10 fail_timeout=48h max_fails=1;
  server 10.0.0.20 backup;
  keepalive 25;
}
server {
  listen 80;
  server_name _;
  client_body_buffer_size 500M;
  client_max_body_size 500M;
  location / {
    proxy_http_version 1.1;
    proxy_pass http://backend;
    proxy_next_upstream timeout invalid_header http_500 http_403;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header Upgrade $http_upgrade;
    #proxy_set_header Connection "";
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Port $server_port;
  }
}

From what I understand the main server works until it becomes unavailable. If it is not available, the backup server will be used. The main server will be used only after 48h according to the configuration. So much for theory.

Everything was fine until the main server was unavailable for a few seconds. Unfortunately, according to logs, backup is used but sometimes the main as well.

I'll try to modify fail_timeout and max_fails variables but no luck.

Ideally, after switching to backup, all requests would be executed there. Only after the time set in fail_timeout elapsed, it returned to the main server.

The process performed by the my API is multi-stage and must be started and completed on the same server.

0 Answers0