在线词典

linux下查看nginx服务状态

更新日期:2026-11-12 20:29:25

```

输出示例:

```

root1234 10 10:30 ?00:00:01 nginx: master process /usr/sbin/nginx

www-data123512340 10:30 ?00:00:00 nginx: worker process

```

如果有相关进程,说明Nginx正在运行。

3. 检查端口监听

```bash

ss -tuln

```

输出示例:

```

tcpLISTEN 010:80:users:(("nginx",1234,6))

```

如果有输出,说明Nginx正在监听80端口。

4. 配置检查

```bash

nginx -t

```

如果输出如下,则配置无误:

```

nginx: configuration file /etc/nginx/nginx.conf test is successful

```

否则,需根据提示修改配置。

三、常见问题排查建议

标题linux下查看nginx服务状态
内容

在日常的Linux服务器运维工作中,经常需要查看Nginx服务的状态,以确保其正常运行。以下是几种常见的方法,适用于不同环境和配置的Linux系统,帮助用户快速判断Nginx是否处于运行、停止或异常状态。

一、常用命令总结

命令 说明 是否需要root权限
`systemctl status nginx` 查看Nginx服务状态(适用于使用systemd的系统) 否(普通用户可执行)
`service nginx status` 查看Nginx服务状态(适用于使用init的系统) 否
`ps -ef grep nginx` 查看是否有nginx进程运行 否
`netstat -tuln grep 80` 或 `ss -tuln grep 80` 检查80端口是否被监听 否
`curl http://127.0.0.1` 测试本地访问Nginx是否正常 否
`nginx -t` 检查Nginx配置文件是否正确 否
`journalctl -u nginx` 查看Nginx服务日志(适用于systemd系统) 否

二、具体操作示例

1. 使用 `systemctl` 查看状态

```bash

systemctl status nginx

```

输出示例:

```

● nginx.service - A high performance web server and reverse proxy server

Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)

Active: active (running) since Thu 2025-04-04 10:30:00 CST; 2h 10min ago

Docs: man:nginx(8)

Main PID: 1234 (nginx)

Tasks: 2 (limit: 4915)

CGroup: /system.slice/nginx.service

├─1234 nginx: master process /usr/sbin/nginx

└─1235 nginx: worker process

```

如果显示 `active (running)`,表示Nginx正在运行。

2. 使用 `ps` 查看进程

```bash

ps -ef

grep nginx grep 80
问题现象 可能原因 解决方法
Nginx无法启动 配置错误、端口冲突、权限问题 使用 `nginx -t` 检查配置;查看日志文件 `/var/log/nginx/error.log`
端口未监听 Nginx未运行、配置错误 使用 `systemctl status nginx` 确认服务状态
页面无法访问 防火墙限制、配置错误 检查防火墙设置;确认配置文件中server块是否正确

通过以上方式,可以高效地判断和排查Nginx服务状态,确保网站或应用的稳定性与可用性。

随便看