Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify if nginx is running or not?

Tags:

nginx

mono

ubuntu

People also ask

How can I tell if Nginx is running?

Through a simple command you can verify the status of the Nginx configuration file: $ sudo systemctl config nginx The output will show if the configuration file is correct or, if it is not, it will show the file and the line where the problem is.


Looking at the requirement you have, the below command shall help:

service nginx status

This is probably system-dependent, but this is the simplest way I've found.

if [ -e /var/run/nginx.pid ]; then echo "nginx is running"; fi

That's the best solution for scripting.


You could use lsof to see what application is listening on port 80:

sudo lsof -i TCP:80

If you are on mac machine and had installed nginx using

brew install nginx

then

brew services list

is the command for you. This will return a list of services installed via brew and their corresponding status.

enter image description here


The modern (systemctl) way of doing it:

systemctl is-active nginx

You can use the exit value in your shell scripts as follows:

systemctl -q is-active nginx && echo "It is active, do something"