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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With