设置Nginx实现容错功能

huangapple go评论67阅读模式
英文:

Setting up nginx for fault tolerance

问题

我有两台后端服务器。我需要配置nginx配置,以便当一台服务器出现故障时,切换到第二台后端服务器。

不幸的是,我只找到了关于多个后端服务器之间的负载分配的信息。

我以前没有使用过nginx,只了解标准配置设置。

英文:

I have two backend server. I need to configure the nginx config so that when one server falls off, it switches to the second backend server

Unfortunately I found only about load distribution between several backend servers

I didn't work with nginx before only standart config setting

答案1

得分: 0

好的,以下是翻译好的部分:

"Okey, it was so easy
In config need add directive

upstream backends {
server backend1;
server backend2 backup;
}

Backup - is options for 2nd server is the one that will rise when 1st server goes down.

After that in directive location / {}
You need add

proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;

proxy_next_upstream - this shows for which returned errors it is necessary to transfer to another server. And when it catch this errors, he can change backend1 to backend2(backup server)"

英文:

Okey, it was so easy
In config need add directive

upstream backends {
   server backend1;
   server backend2 backup;
}

Backup - is options for 2nd server is the one that will rise when 1st server goes down.

After that in directive location / {}
You need add

proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;

proxy_next_upstream - this shows for which returned errors it is necessary to transfer to another server. And when it catch this errors, he can change backend1 to backend2(backup server)

huangapple
  • 本文由 发表于 2023年7月17日 18:43:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定