nginx負載均衡和故障轉(zhuǎn)移

upstream配置如下:

#user  nobody;
worker_processes 1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';
#access_log  logs/access.log  main;
    sendfile on;
#tcp_nopush     on;
#keepalive_timeout  0;
    keepalive_timeout 65;
#這里的域名要和下面proxy_pass的一樣
    upstream test {
        server localhost:8000  weight=1 max_fails=1 fail_timeout=5s;
#發(fā)生錯誤一次,隔5秒再啟用這個服務(wù)器
        server localhost:3000  weight=1 max_fails=1 fail_timeout=5s;
    }
#gzip  on;
    server {
        listen 8080;
        server_name test;
#charset koi8-r;
#access_log  logs/host.access.log  main;
        location / {
            root html;
            index index.html index.htm;
#對應(yīng)上面的test,代理的地址
            proxy_pass http://test;
#故障轉(zhuǎn)移
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_403 http_404 http_429 non_idempotent;
#將請求傳遞到下一個服務(wù)器可以通過嘗試次數(shù)和時間來限制,限制請求可以傳遞到下一個服務(wù)器的時間。 0值關(guān)閉此限制。
            proxy_next_upstream_timeout 0;
#限制將請求傳遞到下一個服務(wù)器的可能嘗試次數(shù)。 0值關(guān)閉此限制。
            proxy_next_upstream_tries 0;
            proxy_read_timeout 5s;
            proxy_connect_timeout 5s;
            proxy_send_timeout 10s;
        }
        location = /50x.html {
            root html;
        }
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
        error_page 500 502 503 504  /50x.html;
    }
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容