What to do when Nginx crashes?

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to troubleshoot, and what commands to run when Nginx process stops working.

Nginx like any other webserver or app can crash from time to time, and when Nginx crashes your website will also stop being online because Nginx is the web server that you are using for your website.

Now there's no way to prevent Nginx from crashing because well anything can go bad, but if you are using Nginx on your production website, to avoid long downtime you can simply restart nginx when Nginx process crashes.

The restart, start, and stop commands for NGINX, is the same on any debian based distro. However, in this tutorial, we are using Ubuntu 22.04.

Restarting Nginx on Ubuntu 22.04

To restart Nginx, is quite simple, and it can be done from the panel of your server or via terminal on the SSH server.

Login on your server, and run the command below to restart your Nginx web server

sudo systemctl restart nginx

Starting Nginx on Ubuntu 22.04

There are cases when restarting command won't work. In this case, you can try to start Nginx manually. To do this, simply run the command below

sudo systemctl start nginx

Stopping Nginx on Ubuntu 22.04

Sometimes you need to stop Nginx process first before starting it manually. To stop Nginx process, you can do so by using the stop command

sudo systemctl stop nginx

And NGINX process should now be stopped, and you should see a similar output on your terminal.

Checking Nginx process Status

Whether you restarted, started or stopped nginx process, to make sure that the command that you issues was effective, you need to check status of Nginx. To do so, you can use the status command

sudo systemctl status nginx

Once you run the status command above, you will see whether Nginx process is running or not.

Conclusion

In this tutorial, you learned how to restart, start and stop Nginx process when it crashes on your server.

The commands we showed you in this tutorial, won't prevent your Nginx web server from crashing, but it will help you to troubleshoot it when it happens. It is important to inspect your Nginx setup and try to identify the root cause of the crash.

I hope this tutorial, helped you solving this issue with your Nginx web server.