超時重試思考-非冪等請求

paraller發表於2017-10-24

轉載請註明出處 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模組(三)

相關文章