有多种方法可以查看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服务是否正在运行。