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

How to automatically restart Nginx when it goes down

· 52CE 我爱测

I have deployed my application onto AWS EC2 and I want to implement automation where if I restart my instance or when the Nginx web server is down, it will restart by itself. I do not really know where to start with this. I heard…

问题原文

原帖链接 · Newbee Coding · CC BY-SA 4.0

I have deployed my application onto AWS EC2 and I want to implement automation where if I restart my instance or when the Nginx web server is down, it will restart by itself. I do not really know where to start with this.

I heard I can use crontab to schedule automatic monitoring and if it is down, it can send email alerts and restart the webserver.

社区高分解答

原帖链接 · Simon Richter · CC BY-SA 4.0

You already have lots of answers how to do it, but I'd investigate what is happening to make it shut down in the first place, and fix that.

When nginx crashes, all currently running requests will be terminated in an unknown state -- files half-transferred, API calls unreplied. In principle the application on top should deal with this, in practice they seldom do, but at that layer it will manifest as weird and unreproducible behaviour, giving the people using the service an feeling of instability (and rightfully so).

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

资料来源与适用范围

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

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

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