1

转载请注明出处 http://www.paraller.com
原文排版地址 点击跳转

转载请注明出处 来源:paraller's blog

upstream www.paraller.com {
        server 10.29.209.14*:3810;
        server 10.24.225.11*:3810;
        server 10.25.208.38*:3810;
}

server {
  server_name www.paraller.com;
  listen 80 ;
  access_log /var/log/nginx/access.log vhost;
  return 301 https://$host$request_uri;
}


server {
        server_name www.paraller.com;
        listen 443 ssl http2 ;
        access_log /var/log/nginx/access.log vhost;
      

        add_header Strict-Transport-Security "max-age=31536000";
           location ^~ /socket.io/ {
        return 301;
    }
    location / {
                proxy_pass http://www.paraller.com;
                proxy_connect_timeout 20;
                proxy_read_timeout 20;
                proxy_send_timeout 20;
                proxy_ignore_client_abort on;
        }
}
  • proxy_connect_timeout 后端服务器连接的超时时间_发起握手等候响应超时时间
  • proxy_read_timeout 连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理(也可以说是后端服务器处理请求的时间)
  • proxy_send_timeout :后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据

nginx在某个版本更新之后,对非幂等的请求不会进行重试处理。

如果要对幂等操作重试请求

In case of upstream returning 429, I'd like to have nginx retry next upstream server. Since nginx by default won't retry non-idempotent requests, how do I force nginx to retry when receiving 429? I imagine this should be the default behavior anyway, or does nginx not care about returning code and will never retry non-idempotent?

If you want nginx to retry non-idempotent requests, you can do so with "proxy_next_upstream non-idempotent;", see http://nginx.org/r/proxy_next...

http://nginx.2469901.n2.nabble.com/upstream-429-and-non-idempotent-request-td7600353.html

优先参考上面的回答,下面是 stackflow的示例:

upstream backends {
    server 192.2.0.1;
    server 192.2.0.2;
    ...
}

server {
    ...

    location / {
        proxy_pass http://backends;
        proxy_next_upstream error timeout http_404;
    }
}

参考网站

https://stackoverflow.com/questions/12868683/nginx-proxy-next-upstream-doesnt-work
https://stackoverflow.com/questions/40661246/nginx-tries-to-proxy-pass-to-upstream-name

关于该参数的详细解释
nginx proxy_next_upstream

Nginx学习总结:proxy与rewrite模块(三)


paraller
207 声望12 粉丝