[英]How do i restart NGINX daemon Process in linux server if a website hosted on the same server fails to load?
我有一个网站托管在 ubuntu 20.04 上运行的 linux 服务器上。 有时网站无法加载并且它也会导致生产停机,如果重新启动 nginx 进程,它就会工作。 So How do i write a script in python or shell script to restart nginx process only if the website goes down with a http code - 502?
首先,我建议您调查问题的根本原因 - 是什么导致 nginx 进程失败? 您的服务器是否正在启动不同的进程并用完 memory? 像ntop这样的工具可以在这里提供帮助。
其次,要在 nginx 服务宕机时自动重启,您可以通过运行sudo systemctl edit nginx
并添加代码片段来编辑nginx.service
文件:
[Service]
Restart=on-failure
这将确保如果进程失败,它将自动重新启动。 话虽这么说,我强烈建议首先调查根本原因,以避免将来出现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.