title: how to deal with failover primary service when using mirroring nginx?
body: <p>I have to flask app that both are the same, running on port 8080 and 8081.
  service 8080 is primary.
  I want to mirror request to 8081.
  till now everything works with following nginx config file.
  but when the primary service (8080) goes down, nginx return 502.
  how to configure</p>
  <pre><code>pid /run/nginx.pid;
  include /etc/nginx/modules-enabled/*.conf;
  events {
          worker_connections 768;
          # multi_accept on;
  }
  
  
  http {
          include /etc/nginx/mime.types;
          default_type application/octet-stream;
  
          access_log /var/log/nginx/access.log;
          error_log /var/log/nginx/error.log;
  
  upstream backend {
      server localhost:8080;
  
   }
  
  upstream test_backend {
      server localhost:8081;
  }
  
  server {
      server_name mirroring;
      listen 80;
  
      access_log /var/log/nginx/proxy.log;
      error_log /var/log/nginx/proxy.error.log info;
  
      location / {
          mirror /mirror;
          proxy_pass http://backend;
      }
  
      location = /mirror {
          proxy_pass http://test_backend$request_uri;
      }
  
    }
  }
  </code></pre>
  <p>How to adjust this issue to overcome request not responding.</p>