简体   繁体   中英

How do i restart NGINX daemon Process in linux server if a website hosted on the same server fails to load?

I have a website which is hosted on a linux server running on ubuntu 20.04. Sometimes the website fails to load & it is causing downtime in production as well and it works if nginx process is restarted. 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?

Firstly, I would recommend looking into the root cause of your issue - what is causing the nginx process to fail? Is your server starting a different process and running out of memory? Tools like ntop can help here.

Secondly, to automatically restart the nginx service when it goes down, you can edit the nginx.service file by running sudo systemctl edit nginx and adding the snippet:

[Service]
Restart=on-failure

This will ensure that if the process fails, it will restart automatically. This being said, I highly recommend looking into the root cause first in order to avoid issues in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM