nginx 报错502Bad Gateway

时间:2023-03-09 04:20:30
nginx 报错502Bad Gateway

场景: 目前在ECS中起了多个node服务,使用forever进程守护,最近,打开线上页面发现报错502 Bad Gateway;同时部分静态资源访问不到.(之前可以的);

解决: 
首先查看nginx的日志信息,基本为如下重复;

2017/04/25 22:09:45 [warn] 25037#0: *12 an upstream response is buffered to a temporary file /usr/local/nginx/proxy_temp/3/00/0000000003 while reading upstream, client: 125.119.1.1, server: channel.zhaoleilei.cn, request: “GET /build/common.js HTTP/1.1”, upstream: “http://127.0.1.1:2000/build/common.js“, host: “channel.zhaoleilei.cn”, referrer: “http://channel.zhaoleilei.cn/login” 
2017/04/25 22:09:54 [info] 25037#0: *12 client prematurely closed connection while sending to client, client: 125.119.1.1, server: channel.zhaoleilei.cn, request: “GET /build/common.js HTTP/1.1”, upstream: “http://127.0.1.1:2000/build/common.js“, host: “channel.zhaoleilei.cn”, referrer: “http://channel.zhaoleilei.cn/login

上网查找原因,未果。感觉问题出在了nginx或者forever这里;打开nginx.conf尝试修改配置时发现报错E514: write error (file system full?);找到原因,说是磁盘满了。查看ubuntu磁盘空间用满的处理方法解决问题。

结论: 出现这个问题的原因在于forever的临时log日志过大,导致磁盘满了,删除日志即可。

拓展: 做定时任务日志切割,以天为单位做压缩备份(可以通过脚本实现),保留一定时间以备查看,有需要可以做日志分析。