问题:一个请求被重复提交,原因是nginx代理后面挂着2个服务器,请求超时的时候(其实已经处理了),结果nigix发现超时,有把请求转给另外台服务器又做了次处理。
我当时的nginx配置:
location ~ /apollo {
limit_req zone=pin burst=20;
rewrite /apollo/(.*) /$1 break;
proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcat_apollo;
expires 0;
}
分析:代码中配置了proxy_next_upstream这个选项。此选项标识tomcat返回以下(http_500 http_502 http_503 http_504 error timeout invalid_header)错误码都会进行重试另外一台服务器。这个对于读请求没有关系,如果对于写请求就会发生多次提交事件。
解决方案:去掉proxy_next_upstream.
参考:http://nginx.org/en/docs/http/ngx_http_proxy_module.html
http://blog.csdn.net/mj158518/article/details/49847119