大网数据广告活动
服务器运维问答

EC2 instance running nginx crashes, "connection refused" - how do I monitor for this?

· 52CE 我爱测

Say nginx on an EC2 instance crashes. The instance is healthy and CloudWatch Metrics are great, but all the domains hosted on the server are now "Connection refused". This seems like a very basic function - monitoring to ensure a…

问题原文

原帖链接 · Neal · CC BY-SA 4.0

Say nginx on an EC2 instance crashes. The instance is healthy and CloudWatch Metrics are great, but all the domains hosted on the server are now "Connection refused".

This seems like a very basic function - monitoring to ensure a website is returning a 200. Is this somewhere in CloudWatch? I would think something could just curl -s -o /dev/null -w "%{http_code}" http://www.example.org/ and if it doesn't receive a return code of 200, say 5 times in a row, it will trigger an instance restart and SNS notification.

Perhaps there is something I should be running on the EC2 instance that would restart nginx if something is unreachable? Either way, I'd love to know how to do this with an AWS resource, so I could even monitor any site and kick off an SNS.

Sorry if I'm missing something easy here. It just seems this would something easily searched, but I have spent hours across months trying to figure this out.

已采纳解答

原帖链接 · MLu · CC BY-SA 4.0

This is typically the job for a load balancer (ALB or ELB) that can detect whether the web server on the instance is running or not and if not you can trigger some action through CloudWatch. Again, typically, an instance replacement through Auto Scaling Group.

It’s perfectly normal to use ASG and ALB even if you need only a single instance.

Alternatively you can create Custom CloudWatch metrics using the CW agent installed on the instance. Then you can report anything you want.

Hope that helps :)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-01-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。