温馨提示×

Ubuntu如何重启Apache

小樊
45
2026-08-27 13:47:55
栏目: 智能运维

在 Ubuntu 上重启 Apache,常用以下几种方式(任选其一即可):

方法一:使用 systemctl(推荐,适用于 Ubuntu 16.04 及以后)

sudo systemctl restart apache2

方法二:使用 service 命令(较老方式,仍可用)

sudo service apache2 restart

方法三:使用 Apache 自带脚本(较少用)

sudo /etc/init.d/apache2 restart

常用相关命令

  • 启动 Apache
    sudo systemctl start apache2
    
  • 停止 Apache
    sudo systemctl stop apache2
    
  • 重新加载配置(不中断连接,推荐修改配置后用)
    sudo systemctl reload apache2
    
  • 查看运行状态
    sudo systemctl status apache2
    

注意事项

  1. 权限问题:需要 sudo 权限。
  2. 配置错误:如果重启失败,可先测试配置:
    sudo apache2ctl configtest
    
  3. 防火墙:如果重启后无法访问,检查是否放行 80/443 端口(如 ufw)。

如果你是在 Docker / 云服务器 / 宝塔面板 环境下,也可以告诉我,我给你更具体的步骤。

0 踩