How to check whether nginx is started in linux

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.

Tools/Materials

 
  • Linux
  • Nginx

Judging by the process

 
  1. 1

    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. 

    How to check whether nginx is started in linux
  2. 2

    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.

    How to check whether nginx is started in linux
    END

Judging by port

 
  1. 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.

    How to check whether nginx is started in linux
  2. 2

    Fourth method: use the lsof command

    lsof -i:80 can also check whether there is a process running on port 80.

    How to check whether nginx is started in linux

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324605790&siteId=291194637