proxy_next_upstream带来的坑和加载sticky模块

1.若nginx配置的响应等待时间(proxy_read_timeout)为30秒,就会触发超时重试,将请求又打到另一台。如果处理中没有考虑到重复数据的场景,就会发生数据多次重复插入!

  proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | off ...;  

  proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;

如果192.168.0.1这台服务器返回了超时或者500,那么访问 /example/ 时应该会自动重试到下一台服务器去,即到192.168.0.2去。

proxy_next_upstream error timeout http_500 non_idemponent;
proxy_connect_timeout 30s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;

  默认情况下,当请求服务器发生错误或超时时,会尝试到下一台服务器。 参考:https://blog.csdn.net/bujidexinq/article/details/80406149

2.proxy_next_upstream error timeout http_500 non_idemponent;

像 post, lock, patch 这种会对服务器造成不幂等的方法,默认是不进行重试的,如果一定要进行重试,则要加上这个配置。

https://zhuanlan.zhihu.com/p/35803906

3.Nginx安装Sticky模块

  https://www.cnblogs.com/powerwu/articles/12619260.html

原文地址:https://www.cnblogs.com/hixiaowei/p/14218619.html