• nginx重试机制proxy_next_upstream


    nginx作为反向代理服务器,后端RS有多台服务器,上层通过一定机制保证容错和负载均衡。

    nginx的重试机制就是容错的一种

    官方链接:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream

    proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | http_429 | non_idempotent | off ...;
    Default: proxy_next_upstream error timeout;
    Context: http, server, location

    指定应将请求传递到下一个服务器的情况:
    error # 与服务器建立连接,向其传递请求或读取响应头时发生错误;
    timeout # 在与服务器建立连接,向其传递请求或读取响应头时发生超时;
    invalid_header # 服务器返回空的或无效的响应;
    http_500 # 服务器返回代码为500的响应;
    http_502 # 服务器返回代码为502的响应;
    http_503 # 服务器返回代码为503的响应;
    http_504 # 服务器返回代码504的响应;
    http_403 # 服务器返回代码为403的响应;
    http_404 # 服务器返回代码为404的响应;
    http_429 # 服务器返回代码为429的响应(1.11.13);
    non_idempotent # 通常,请求与 非幂等 方法(POST,LOCK,PATCH)不传递到请求是否已被发送到上游服务器(1.9.13)的下一个服务器; 启用此选项显式允许重试此类请求;
    off # 禁用将请求传递给下一个服务器。
    下面还有一个参数影响重试次数,0表示不限制。:

    Syntax: proxy_next_upstream_tries number;
    Default: proxy_next_upstream_tries 0;
    Context: http, server, location
    举例如下:

    upstream app-proxy {
    server 192.168.5.100:8080;
    server 192.168.5.101:8080;
    check interval=2000 rise=1 fall=3 timeout=3000 type=http;
    check_keepalive_requests 1;
    # check_http_send "HEAD /status/status.html HTTP/1.1 ";
    check_http_send "GET /status/status.html HTTP/1.1 Connection: close Host: localhost ";
    check_http_expect_alive http_2xx http_3xx;
    }

    location / {
    proxy_pass http://app-proxy;
    proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
    proxy_next_upstream_tries 3;
    proxy_connect_timeout 60s;
    proxy_read_timeout 60s;
    proxy_send_timeout 60s;
    proxy_pass_request_headers on;
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    set $domain default;
    ————————————————
    版权声明:本文为CSDN博主「流浪猫之家」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/christ1208/article/details/106949000

  • 相关阅读:
    自定义实现wcf的用户名密码验证
    EF6:编写你自己的code first 数据迁移操作(睡前来一篇,翻译的)
    .net 连接Redis
    idea external libraries 只有jdk问题
    MAC vim安装gruvbox主题
    Mac gitk安装与优化
    spring security 4 filter 顺序及作用
    mysql 采样查询 / 间隔查询 / 跳跃查询的两种实现思路
    nginx warn an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/ while reading upstream
    nginx日志 logrotate配置
  • 原文地址:https://www.cnblogs.com/telwanggs/p/15107029.html
Copyright © 2020-2023  润新知