004_Nginx 499错误的原因及解决方法
一、
今天进行系统维护,发现了大量的499错误,
499错误
ngx_string(ngx_http_error_495_page), /* 495, https certificate error */
ngx_string(ngx_http_error_496_page), /* 496, https no certificate */
ngx_string(ngx_http_error_497_page), /* 497, http to https */
ngx_string(ngx_http_error_404_page), /* 498, canceled */
ngx_null_string, /* 499, client has closed connection */
可以看到,499对应的是 “client has closed connection”。这很有可能是因为服务器端处理的时间过长,客户端“不耐烦”了。
Nginx 499错误的原因及解决方法
打开Nginx的access.log发现在最后一次的提交是出现了HTTP1.1 499 0 -这样的错误,在百度搜索nginx 499错误,结果都是说客户端主动断开了连接。
但经过我的测试这显然不是客户端的问题,因为使用端口+IP直接访问后端服务器不存在此问题,后来测试nginx发现如果两次提交post过快就会出现499的情况,看来是nginx认为是不安全的连接,主动拒绝了客户端的连接.
但搜索相关问题一直找不到解决方法,最后终于在google上搜索到一英文论坛上有关于此错误的解决方法。
proxy_ignore_client_abort on;
Don’t know if this is safe.
说要配置proxy_ignore_client_abort on;
意思代理服务端不要主要主动关闭客户端连接。
配置重启nginx,问题果然得到解决。只是安全方面稍有欠缺,但比总是出现找不到服务器好多了。
也可参看其他案例:http://yucanghai.blog.51cto.com/5260262/1713803
二、
业务有一个下载Excel表格的需求,可以忍受很长的下载时间。由于开发对后端server的gc等还没有优化,业务又着急使用。因为apigateway有30s的超时时间限制。Nginx假如后端服务器端处理的时间过长,客户端“不耐烦”,Nginx就会在日志返回如下的499。
(1)Nginx不加这个参数前的日志为
1 | 10.600.254.35 10.600.254.35 2017-10-13T19:33:30+08:00 www.jyall.me^^11D9642583DF4E719736503E82DC4A3D|1507894380805 GET 499 /jyall/v1/minos/order/export ?selectedFields=merchantId%2CmerchantName%2CpartnerOrderCode%2CtrackingId%2CserviceName%2CeffectivenessName%2CreceiverName%2CreceiverPrimaryPhone%2CreceiverCityName%2CreceiverAddress%2CreceiverLocation%2CorderWeight%2CtransportName%2CtransportAddress%2CcarrierLocation%2CtransportTel%2CcomplaintStatus%2CcomplaintDescription%2CdeliveryCost%2CtimeExtraCost%2CdistanceExtraCost%2CweatherExtraCost%2CweightExtraCost%2CtotalDeliveryCost%2CdiscountCost%2CtotalFee%2CorderAddTime%2CrequireReceiveTime%2CapolloOrderCreateTime%2CdispatchTime%2CtakeMealTime%2CtoStoreTime%2CstartDeliveryTime%2CarrivalDateTime%2CdeliveriedTime%2CagentId%2CagentName%2CstationId%2CcarrierTeamName%2CcarrierDriverName%2CcarrierDriverPhone%2CorderStatusName%2CdeliveryDistance%2CorderTimeout%2CabnormalDesc%2CtrackingRemark%2CmajorBusiness&startCreatedAt=1507824000000&endCreatedAt=1507910340000 |
proxy_ignore_client_abort on; #让Nginx代理服务端不要主动关闭客户端的连接。
(2)加上这个参数后去掉限制后,nginx不再返回499,而是200了
1 | 10.600.254.35 10.600.254.35 2017-10-13T19:38:49+08:00 jyall-admin.jyall.com^^78882C98800A47E8A7D1EA9CD1A2C190|1507894686022 GET 200 /jyall/v1/minos/order/export ?selectedFields=merchantId%2CmerchantName%2CpartnerOrderCode%2CtrackingId%2CserviceName%2CeffectivenessName%2CreceiverName%2CreceiverPrimaryPhone%2CreceiverCityName%2CreceiverAddress%2CreceiverLocation%2CorderWeight%2CtransportName%2CtransportAddress%2CcarrierLocation%2CtransportTel%2CcomplaintStatus%2CcomplaintDescription%2CdeliveryCost%2CtimeExtraCost%2CdistanceExtraCost%2CweatherExtraCost%2CweightExtraCost%2CtotalDeliveryCost%2CdiscountCost%2CtotalFee%2CorderAddTime%2CrequireReceiveTime%2CapolloOrderCreateTime%2CdispatchTime%2CtakeMealTime%2CtoStoreTime%2CstartDeliveryTime%2CarrivalDateTime%2CdeliveriedTime%2CagentId%2CagentName%2CstationId%2CcarrierTeamName%2CcarrierDriverName%2CcarrierDriverPhone%2CorderStatusName%2CdeliveryDistance%2CorderTimeout%2CabnormalDesc%2CtrackingRemark%2CmajorBusiness&startCreatedAt=1507824000000&endCreatedAt=1507910340000 HTTP HTTP /1 .1 43.735 43.735 2229 32768 211088 10.200.62.152:8080 -application /vnd .ms-excel;charset=utf-8 application /vnd .ms-excel;charset=utf-8 jyall-admin.jyall.com apirouter user al al-channel-statble-1 APIRouter 1.0 bj-jyall-web-1 Mozilla /5 .0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit /537 .36 (KHTML, like Gecko) Chrome /61 .0.3163.100 Safari /537 .36 - |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!