有多種方法可以查看Nginx服務是否運行,以下是其中一種方法:
sudo systemctl status nginx
如果Nginx服務正在運行,您將看到類似以下輸出:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-09-27 15:53:12 UTC; 1 day 5h ago
Docs: man:nginx(8)
Process: 2535 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2536 ExecStartPost=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2537 (nginx)
Tasks: 2 (limit: 2295)
CGroup: /system.slice/nginx.service
├─2537 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2538 nginx: worker process
如果Nginx服務未運行,您將看到類似以下輸出:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2021-09-27 15:53:12 UTC; 1 day 5h ago
Docs: man:nginx(8)
Process: 2535 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2536 ExecStartPost=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2537 (code=exited, status=0/SUCCESS)
無論使用哪種方法,都可以很容易地檢查Nginx服務是否正在運行。