在Linux服务器运维生产环境的时候,会要检查Nginx运行状态。这里我们会用到这些常见命令。
1、使用 systemctl(推荐,适用于 systemd 系统)
sudo systemctl status 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 2025-02-10 10:00:00 UTC; 1h 23min ago
如果没有正常运行会看到:
● 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)
2、检查 Nginx 进程是否存在
ps aux | grep nginx
正常运行会看到:
root 1234 0.0 0.1 12345 6789 ? Ss 10:00 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 1235 0.0 0.2 23456 7890 ? S 10:00 0:00 nginx: worker process
无进程:若无输出,则 Nginx 未运行。