title: Nginx TCP proxy with load balancer
body: <p>I tried to create nginx tcp proxy for patroni (postgresql) databases.</p>
  
  <p><strong>15432</strong> - postgresql</p>
  
  <p><strong>8008</strong> - patroni, <strong>HTTP 200</strong> if ok, all other - errors</p>
  
  <p>For work i use ngx_stream_core_module and ngx_stream_upstream_check_module.
  For every node i create</p>
  
  <pre><code>stream {
  ...
    upstream db {
      server 127.0.0.1:15432;
      check interval=3000 rise=2 fall=5 timeout=1000 port=8008 type=http;
      check_http_send "HEAD / HTTP/1.0\r\n\r\n";
      check_http_expect_alive http_2xx http_3xx;
    }
    server {
      listen 15434;
      proxy_bind 127.0.0.1;
      proxy_connect_timeout 4s;
      proxy_timeout 100s;
      proxy_pass db;
      #return 444;
    }
   ...
  }
  </code></pre>
  
  <p>cluster config</p>
  
  <pre><code>  upstream db_cluster {
      server 192.168.8.201:15434 max_fails=3 fail_timeout=10s;
      server 192.168.8.202:15434 max_fails=3 fail_timeout=10s;
    }
    server {
      listen 5432;
      proxy_connect_timeout 100s;
      proxy_timeout 100s;
      proxy_pass db_cluster;
    }
  </code></pre>
  
  <p>But when all upstreams are died i need to return tcp refuse (or somethink another)?</p>