Answer the question
In order to leave comments, you need to log in
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;
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question