Loadbalancer application on nodejs using nginx sticks in Chrome, why?

In Docker, among other things, raised 2 node and nginx server as a loadbalancer.

upstream localhost {
server node1:3000;
server node2:3000;
}

server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost;
proxy_set_header Host $Host;
}
}


Everywhere works fine, servers when you upgrade change, except in Chrome. I have the feeling that the cache interferes. Then on the 1st server sticks, on the 2th.

Tell me what the problem is.
April 19th 20 at 12:39
2 answers
April 19th 20 at 12:41
Perhaps the bug is in the cache, perhaps. Try in incognito to open, to clear the cache.
April 19th 20 at 12:43
localhost is a registered service name. In the config it with you refers to your local host 127.0.0.1 comparable and at the same time a pool of servers to balance. Accordingly, you have a logical error.

Probably your config should look something like this:
http {
 upstream MyNodeApp {
 // ip_hash - it is better to install more, you can look here
 // https://nginx.org/en/docs/http/load_balancing.html
ip_hash;
 server node1:3000;
 server node2:3000;
}

 server {
 listen 80;
 // If you just need to respond to the request from 80 port on any name, then you can comment out server_name
 server_name my-server-name.ru;

 location / {
 proxy_pass http://MyNodeApp;
 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;
}
}
}
with your config sticks everywhere and always on the last server. - Raegan97 commented on April 19th 20 at 12:46

Find more questions by tags Node.jsGoogle ChromeNginx