Nginx is a high-performance reverse proxy server. Now it is generally used as the first-level proxy for our website or other web services. The Nginx service is the first thing a user requests in a browser.
If the Nginx service is not started or ends abnormally, the normal use of the web service will be affected.
Next, I will share the process record of checking whether Nginx is started in Linux.
Judging by the process
-
The first method: view the process list and filter
Every application running in Linux will generate a process, then we can judge whether it is started by checking whether the Nginx process exists.
List the processes with ps -ef, then filter by grep.
For example: ps -ef | grep nginx to see if the Nginx process exists.
-
The second method: directly view the process id
ps -C nginx -o pid
This method of directly returning the pid is more suitable for use in combination with other programs, such as executing this command in a shell/python script to get the pid, and then judge whether Nginx is started according to the pid.
This method is recommended.
END
Judging by port
-
The third method: use the netstat command
If our Nginx is running on port 80, then we can use the netstat -anp | grep :80 command to determine whether Nginx is started.
-
Fourth method: use the lsof command
lsof -i:80 can also check whether there is a process running on port 80.