title: nginx not loadbalancing in case of ip_hash
body: <p>I am trying to use <code>nginx</code> for loadbalancing. I have to use <code>ip_hash</code> because  I work with websockets. Following is the configuration:</p>
  
  <pre><code>#user  nobody;
  worker_processes 3;
  
  events {
      worker_connections  1024;
  }
  
  
  http {
      include       mime.types;
      default_type  application/octet-stream;
  
  
      sendfile        on;
      #tcp_nopush     on;
  
      #keepalive_timeout  0;
      keepalive_timeout  65;
  
      #gzip  on;
  
      upstream my_http_servers {
          ip_hash;
          server 127.0.0.1:3001;
          server 127.0.0.1:3004;
          server 127.0.0.1:3003;
      }
      server {
          listen       3000;
          server_name  localhost;
  
          #charset koi8-r;
  
          #access_log  logs/host.access.log  main;
  
          location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
  
            proxy_pass http://my_http_servers;
  
            # enable WebSockets
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
  
          }
      }
  }
  </code></pre>
  
  <p>Now I have all the 3 servers and nginx running locally on machine 1 <code>(ip: 192.168.10.2)</code>. 
  I also have a frontend application which calls this backend server. My frontend runs on <code>192.168.10.2:4200</code>.<br>
  When I call the <code>http://192.168.10.2:4200</code> from machine1, it goes to say <code>server1</code>. 
  From my machine2 which is connected to the same WIFI <code>(ip: 192.168.10.23)</code>, I call <code>http://192.168.10.2:4200</code>, but it still goes to <code>server1</code>. 
  <code>ip_hash</code> is not correctly doing load balancing. I am not sure what I am doing wrong, I understand ip_hash will be a sticky connection, so all requests from machine1 should go to server1 but from machine2 it should go to some other servers?</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I even tried using <code>hash $remote_addr;</code> instead of <code>ip_hash</code>, but still all requests are going to the same single server. This is my configuration using hash:</p>
  
  <pre><code>worker_processes 3;
  
  events {
      worker_connections  1024;
  }
  
  http {
      include       mime.types;
      default_type  application/octet-stream;
  
      sendfile        on;
      keepalive_timeout  65;
  
      upstream my_http_servers {
          hash $remote_addr;
          server 127.0.0.1:3001;
          server 127.0.0.1:3002;
          server 127.0.0.1:3003;
      }
      server {
          listen       3000;
          server_name  localhost;
  
          location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
  
            proxy_pass http://my_http_servers;
  
            # enable WebSockets
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
  
          }
      }  
  }
  </code></pre>