負(fù)載均衡 - nginx配置backup服務(wù)器,錯(cuò)誤頁面不生效
問題描述
1.配置nginx備份服務(wù)器時(shí),當(dāng)其他兩臺(tái)服務(wù)器不可用時(shí),跳轉(zhuǎn)到自定義的頁面。但實(shí)際配置后未生效;麻煩看下我配置的哪有毛病呢
安裝nginx主機(jī)的IP:192.168.109.210其他兩臺(tái)安裝apache主機(jī)的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; #設(shè)置錯(cuò)誤頁面 root /data/www/errorpage; index index.html;location / {#設(shè)置反向代理#proxy_pass http://192.168.109.208;proxy_pass http://mysvr;proxy_set_header X-Real-IP $remote_addr; }
}}
3.配置的錯(cuò)誤頁面index.html[root@yunwei109-210 errorpage]# more index.html<h1>sorry,我報(bào)錯(cuò)了!(O_O)</h1>[root@yunwei109-210 errorpage]# pwd/data/www/errorpage
4.報(bào)錯(cuò)信息(停掉其他2臺(tái)服務(wù)器后)
當(dāng)前報(bào)錯(cuò)頁面
正確的報(bào)錯(cuò)頁面sorry,我報(bào)錯(cuò)了!
問題解答
回答1:在http段中增加:
proxy_next_upstream http_404 http_502 error;
詳情請(qǐng)見:http://nginx.org/en/docs/http...http://nginx.org/en/docs/http...
