K
K
Konstantin2022-04-21 12:05:00
Nginx
Konstantin, 2022-04-21 12:05:00

How to balance NGINX?

Hello everyone, help the teapot figure it out. I comprehend NGINX, namely its upstream balancing

. What I have: 3 virtual machines.
1. virtualka NGINX
2 and 3 is a web server

Here is my simple config

upstream web {
    ip_hash;
    server 192.168.1.2:80;  // тут веб 1 
    server 192.168.1.3:80 backup;  // тут веб 2 
}

server {
    listen 80;
    location / {
    proxy_pass http://web/;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    }
}


What is actually my question, everything seems to be running fine until the moment I cut off 192.168.1.2:80 this virtual machine, in theory everything should go to the second spare, but it doesn’t.

Maybe I'm missing some point, maybe somehow the web server needs to be cunningly configured additionally?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lynn "Coffee Man", 2022-04-21
@Lynn

> Maybe I'm missing some point
Yeah, you're missing out. Reading documentation is called


backup
... The parameter cannot be used with the hash, ip_hash , and random
load balancing methods .

nginx.org/ru/docs/http/ngx_http_upstream_module.ht...

A
Alexander Karabanov, 2022-04-21
@karabanov

Here is an answer about ip_hash How to avoid 10 common mistakes in setting up NGINX
But read the rest too.

K
Konstantin, 2022-04-22
@kostya_vtomske

Gentlemen, tell me if it is possible to somehow substitute addresses or domains from upstream in the
proxy_set_header Host (substitute the right one)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question