您的位置:首页技术文章
文章详情页

负载均衡 - nginx配置backup服务器,错误页面不生效

【字号: 日期:2024-06-20 17:06:41浏览:84作者:猪猪

问题描述

1.配置nginx备份服务器时,当其他两台服务器不可用时,跳转到自定义的页面。但实际配置后未生效;麻烦看下我配置的哪有毛病呢

安装nginx主机的IP:192.168.109.210其他两台安装apache主机的IP:192.168.109.208和192.168.109.209

2.代码段

http{

upstream mysvr {

server 192.168.109.208 weight=1 max_fails=2 fail_timeout=2;server 192.168.109.209 weight=1 max_fails=2 fail_timeout=2;server 127.0.0.1:80 backup;}

server {

listen 80; server_name localhost; #设置错误页面 root /data/www/errorpage; index index.html;location / {#设置反向代理#proxy_pass http://192.168.109.208;proxy_pass http://mysvr;proxy_set_header X-Real-IP $remote_addr; }

}}

3.配置的错误页面index.html[root@yunwei109-210 errorpage]# more index.html<h1>sorry,我报错了!(O_O)</h1>[root@yunwei109-210 errorpage]# pwd/data/www/errorpage

4.报错信息(停掉其他2台服务器后)

当前报错页面负载均衡 - nginx配置backup服务器,错误页面不生效

正确的报错页面sorry,我报错了!

问题解答

回答1:

在http段中增加:

proxy_next_upstream http_404 http_502 error;

详情请见:http://nginx.org/en/docs/http...http://nginx.org/en/docs/http...