How to check if Nginx is running or not?
by David Pham • November 7, 2018 • Blog
Nginx is running or not look like an very simple task but sometimes the check command won’t work as it should. In this case, we need some more ways to check. Let me show some all of ways I know about check Nginx running, simply try one by one.
Official command to check Nginx running or not
1 |
service nginx status |
After this command you will see something like this.
In this case, the same information will be shown if you use this command
1 |
/bin/systemctl status nginx.service |
use “Lsof” to check Nginx running
Check port 80 to make sure Nginx is listing port 80. If lsof is not available let’s install it
On CentOS:
1 |
yum install lsof |
On Ubuntu
1 |
sudo apt-get install lsof -y |
Then using this command to check nginx
1 |
lsof -i TCP:80 |
If everything work well, you will see the output like this
Check Nginx running with nmap
Another way to check port 80 to make sure Nginx is running. Let’s run this command
1 |
nmap -sV localhost -p 80 |
If nginx is running, you will see this output
If nmap is not available let’s install it
On CentOS:
1 |
yum install nmap |
On Ubuntu
1 |
sudo apt-get install nmap -y |
Check Nginx running with scripting
Another best way for you to check nginx running with script, simple use this line
1 |
if [ -e /var/run/nginx.pid ]; then echo "nginx is running"; fi |
If nginx is running you will see the output is “nginx is running”.
Goodluck for your job.
References:
https://stackoverflow.com/questions/35220654/how-to-verify-if-nginx-is-running-or-not
https://medium.com/@madhan5000/first-off-check-if-nginx-is-running-e29759bdb2c