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中;