温馨提示×

如何查ubuntu apache2状态

小樊
42
2026-09-23 10:35:23
栏目: 智能运维

在 Ubuntu 上查看 Apache2(apache2 服务)状态,常用方法如下:


1. 使用 systemd(推荐,Ubuntu 15.04+)

systemctl status apache2

说明:

  • 显示是否正在运行(active / inactive)
  • 显示最近日志
  • 按 q 退出

启动 / 停止 / 重启:

sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2

设置开机自启:

sudo systemctl enable apache2

2. 使用 service 命令(兼容旧版本)

sudo service apache2 status

启动 / 停止:

sudo service apache2 start
sudo service apache2 stop
sudo service apache2 restart

3. 查看 Apache 进程

ps aux | grep apache2

或

pgrep -a apache2

4. 查看监听端口(确认是否在运行)

sudo netstat -tlnp | grep apache2
# 或
sudo ss -tlnp | grep apache2

通常应看到 :80 或 :443


5. 查看 Apache 错误/访问日志

sudo tail -f /var/log/apache2/error.log
sudo tail -f /var/log/apache2/access.log

6. 测试配置文件是否正确

sudo apache2ctl configtest

输出 Syntax OK 表示配置无误。


快速判断 Apache 是否运行

systemctl is-active apache2

输出:

  • active → 正在运行
  • inactive → 未运行

如果你是想 通过浏览器确认 或 排查无法访问的问题,也可以告诉我具体现象。

0 踩