title: How to set up two Nginx containers as a reverse proxy in an active-passive set up with failover?
body: <p>I have set up a Nginx container on a Linux-EC2 server. My Nginx config file is as follows:</p>
  
  <pre><code>server {
      listen      80;
      server_name     client-dev.com;
      location / {
          proxy_pass         http://dev-client.1234.io:5001/;
          proxy_redirect     off;
  
          ##proxy_set_header   Host             $host;
          proxy_set_header   X-Real-IP        $remote_addr;
          proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  
          client_max_body_size       10m;
          client_body_buffer_size    128k;
  
          proxy_connect_timeout      90;
          proxy_send_timeout         90;
          proxy_read_timeout         90;
  
          proxy_buffer_size          4k;
          proxy_buffers              4 32k;
          proxy_busy_buffers_size    64k;
          proxy_temp_file_write_size 64k;
      }
  }
  server {
      listen      80;
      server_name     client-test.com;
      location / {
          proxy_pass         http://test-client-1234.io:5005/;
          proxy_redirect     off;
  
          ##proxy_set_header   Host             $host;
          proxy_set_header   X-Real-IP        $remote_addr;
          proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  
          client_max_body_size       10m;
          client_body_buffer_size    128k;
  
          proxy_connect_timeout      90;
          proxy_send_timeout         90;
          proxy_read_timeout         90;
  
          proxy_buffer_size          4k;
          proxy_buffers              4 32k;
          proxy_busy_buffers_size    64k;
          proxy_temp_file_write_size 64k;
      }
  }
  </code></pre>
  
  <p>It passes the requests with different ports to port 80. Now, I need to make a redundant Nginx in an active-passive mode. In case, if the Nginx container goes down/stops.</p>
  
  <p>To do so, would I need to set another Nginx container in the same server? If so, how should it be setup to do the failover automatically? </p>
  
  <p>I have looked at "upstream" option, but as I found, it would not work for this case. The proxy_pass that I have are external and dynamic that I get them using a script from docker-cloud.</p>
  
  <p>There is another way named "docker-gen" however, I'm not sure how much useful it would be, and I prefer to use another way if there is any?</p>
  
  <p>Any help would be appreciated.</p>