在部署一个以nginx为负载均衡的web服务集群中,在nginx异常日志中出现了进程异常退出的日志,导致反向代理的websocket连接断开,通过环境检查和分析,最终确定原因为modsecurity模块问题。
软件版本说明
- nginx-1.15.6
- ModSecurity-nginx_refactoring
最初安装了2.9.3版本,后面发现和nginx存在兼容问题,于是安装了分支版本,该提示点在官网源码下载处有说明。
NOTE: Some instabilities in the Nginx add-on have been reported (see the Github issues page for details). Please use the “nginx_refactoring” branch where possible for the most up to date version and stay tuned for the ModSecurity version 4.
异常现象
web应用中涉及到websocket协议的功能出现异常,并且经过检查,nginx配置中超时设置都正确。
检查nginx异常日志(error.log)文件,有如下日志信息:
2018/11/27 09:41:29 [alert] 4719#4719: worker process 17697 exited on signal 11 (core dumped)
进一步通过dmesg
命令,查看具体日志信息,获得异常问题在libapr
模块中。
[3414523.863955] nginx[17734]: segfault at 10 ip 00007fbf4ce3adc9 sp 00007ffc33a676f0 error 4 in libapr-1.so.0.4.8[7fbf4ce24000+2d000]
[3414603.803353] nginx[17764]: segfault at 10 ip 00007fbf4ce3adc9 sp 00007ffc33a676a0 error 4 in libapr-1.so.0.4.8[7fbf4ce24000+2d000]
[3414620.073383] nginx[17765]: segfault at 10 ip 00007fbf4ce3adc9 sp 00007ffc33a676a0 error 4 in libapr-1.so.0.4.8[7fbf4ce24000+2d000]
初步怀疑由于ModSecurity模块导致nginx进程退出,从而该进程上的websocket连接全部断掉。
在ModSecurity issues列表中发现有同样问题的反馈:https://github.com/SpiderLabs/ModSecurity/issues/658 ,并且表示在版本2中不再予以修复。
No longer a problem in libModSecurity. Marking this as won’t fix in 2.x.
解决方案
升级安装 modsecurity-v3.0.3,通过 ModSecurity-nginx connector 模块和nginx结合,从而解决该问题。