要查看 Nginx 的运行状态,可以通过以下几种方法:
ps aux | grep nginx
nginx: master process
和 nginx: worker process
进程,说明 Nginx 正在运行。systemctl status nginx
active (running)
,以及最近的日志片段。Nginx 默认监听 80
(HTTP)或 443
(HTTPS)端口:
ss -tulnp | grep nginx
# 或
netstat -tulnp | grep nginx
0.0.0.0:80
或 :::80
,说明 Nginx 正在运行。nginx -t # 测试配置文件语法
nginx -s reload # 重新加载配置(不重启服务)
日志路径通常为 /var/log/nginx/error.log
:
tail -f /var/log/nginx/error.log
curl -I http://localhost
HTTP/1.1 200 OK
,说明服务正常。在 Nginx 配置中添加以下内容(通常在 server
块内):
location /nginx_status {
stub_status on;
allow 127.0.0.1; # 仅允许本地访问
deny all;
}
重启 Nginx 后访问 http://localhost/nginx_status
,输出类似:
Active connections: 3
server accepts handled requests
100 100 200
Reading: 0 Writing: 1 Waiting: 2
nginx
或 systemctl start nginx
。www-data
或 nginx
)有权限访问相关文件。根据实际需求选择合适的方法即可快速确认 Nginx 状态。