温馨提示×

Ubuntu怎么重启Apache服务

小樊
36
2026-07-17 19:04:17
栏目: 智能运维

Ubuntu 上重启 Apache 服务,最常用、最推荐的方法是使用 systemctl(适用于 Ubuntu 16.04 及以后版本)。

✅ 方法一:使用 systemctl(推荐)

sudo systemctl restart apache2

✅ 常用 Apache 服务管理命令

# 启动 Apache
sudo systemctl start apache2

# 停止 Apache
sudo systemctl stop apache2

# 重启 Apache
sudo systemctl restart apache2

# 重新加载配置(不中断服务,最常用)
sudo systemctl reload apache2

# 查看运行状态
sudo systemctl status apache2

✅ 方法二:使用 service(旧方式,仍可用)

sudo service apache2 restart

✅ 检查 Apache 是否正常运行

systemctl status apache2

curl -I 127.0.0.1

✅ 修改配置后建议

如果只是修改了配置文件(如虚拟主机),优先使用 reload

sudo systemctl reload apache2

如果你遇到报错或重启失败,可以把错误信息贴出来,我可以帮你具体分析。

0