nginx backup 功能
nginx backup 功能已实现,404 页面不转到备机, 502 503 504 到备机。
配置如下
upstream server_tomcat1 {
server 127.0.0.1:9001 weight=1 max_fails=5 fail_timeout=60s;
server 127.0.0.1:9010 weight=1 max_fails=5 fail_timeout=60s backup;
}
server {
listen 443 ssl;
include /etc/nginx/ssl_certificate/ssl.conf;
server_name test.xx.cn ;
location / {
# root /usr/share/nginx/html;
proxy_next_upstream error timeout http_502 http_503 http_504 ;
proxy_pass http://server_tomcat1/;
proxy_buffer_size 64k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120;
}
location ~ ^/favicon\.ico$ {
access_log off;
deny all;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
#backup参数 ,backup 不能和ip_hash一起使用,backup 参数是指当所有非备机都宕机或者不可用的情况下,就只能使用带backup标准的备机。
#Nginx默认判断失败节点状态以connect refuse和timeout状态为准,不以HTTP错误状态进行判断失败,
HTTP只要能返回状态说明该节点还可以正常连接,所以nginx判断其还是存活状态除非添加了proxy_next_upstream指令设置对404、502、503、504、500和time out等错误转到备机处理,
nginx记录错误数量只记录timeout 、connect refuse、502、500、503、504这6种状态,timeout和connect refuse是永远被记录错误状态,而502、500、503、504只有在配置proxy_next_upstream参数之后nginx才会记录这4种HTTP错误到fails中;
转载于:https://www.cnblogs.com/nickxr/p/10283370.html