开发者社区> 问答> 正文

nginx配置backup服务器,错误页面不生效?报错

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台服务器后)

当前报错页面

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

展开
收起
爱吃鱼的程序员 2020-06-09 16:27:10 1294 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    worker_processes 1;
    events{
      worker_connections 1024;
         }
    http{
      include   mime.types;
      default_type application/octet-stream;
      sendfile    on;
      keepalive_timeout 65;
       
      server{
        listen   80;
        server_name localhost;
        location/{
          root /data/www/errorpage;
          index index.htmlindex.htm;
                }
        error_page 500502503504 /50x.html;
        location=/50x.html{
          root html;
                        } 
    }
     upstream mysvr { 
     server 192.168.109.208:80weight=1;
     server 192.168.109.209:80weight=1;
     server127.0.0.1:80 backup;
     } 
      server{
        listen   192.168.109.210:80;
        server_namemysvr;
        location/{
          index index.htmlindex.htm;
          proxy_pass  http://mysvr;
          proxy_set_header X-Real-IP    $remote_addr;
        }
      }
    }


    貌似是死循环了,本地主机(备份)请求到后段了,本地主机的错误信息多建一个站点,端口不要用80。

    2020-06-09 16:27:29
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载