L
L
lavezzi12020-04-18 10:40:57
Nginx
lavezzi1, 2020-04-18 10:40:57

Loadbalancer of applications on nodejs via nginx sticks in Chrome, why?

In the docker, among other things, 2 nodes and an nginx server were raised as a loadbalancer.


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

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


Everywhere it works fine, the servers change during the update, except in Chrome. It feels like some kind of cache is interfering. That on the 1st server sticks, on the 2nd.

Tell me what's the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2020-04-18
@HistoryART

Maybe a cache bug, maybe. Try to open incognito, clear the cache.

C
cobra-2k, 2020-04-18
@cobra-2k

localhost is the registered service name. In the config, it denotes your local host comparable to 127.0.0.1 and at the same time a pool of servers for balancing. Accordingly, you have a logical error.
Most likely your config should look something like this:

http {
    upstream MyNodeApp {
        // ip_hash - лучше также установить, подробнее можно тут глянуть
        // https://nginx.org/en/docs/http/load_balancing.html
        ip_hash;
        server node1:3000;
        server node2:3000;
    }

    server {
        listen 80;
        // Если нужно просто отвечать на запрос с 80 порта, на любое имя, то 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;
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question