温馨提示×

如何查看apache2状态

小樊
46
2026-10-02 05:03:38
栏目: 编程语言

在常见的 Linux 系统(如 Ubuntu / Debian / CentOS)中,查看 Apache2(httpd)状态 通常有下面几种方式:


一、使用 systemctl(推荐,适用于 systemd 系统)

大多数现代 Linux 都使用 systemd:

systemctl status apache2

(CentOS / RHEL 上服务名是 httpd)

systemctl status httpd

查看是否正在运行、最近日志、PID 等信息。

常用命令:

# 启动
sudo systemctl start apache2

# 停止
sudo systemctl stop apache2

# 重启
sudo systemctl restart apache2

# 开机自启
sudo systemctl enable apache2

二、使用 service 命令(兼容老系统)

sudo service apache2 status

或

sudo service httpd status

三、查看进程是否存在

ps aux | grep apache2

或

ps aux | grep httpd

四、查看端口监听状态

Apache 默认监听 80(HTTP)或 443(HTTPS):

sudo netstat -tunlp | grep :80

或

sudo ss -tunlp | grep :80

五、通过浏览器或 curl 测试

curl -I http://localhost

或

curl http://127.0.0.1

返回 200 OK 说明 Apache 正常工作。


六、查看 Apache 错误日志

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

(CentOS 通常在 /var/log/httpd/error_log)


如果你能告诉我:

  • 使用的是 Ubuntu / CentOS / 其他系统
  • 是 本地服务器还是云服务器
  • 想查看的是 运行状态 / 性能 / 访问情况

我可以给你更精确的建议。

0 踩