温馨提示×

ubuntu apache2如何启用

小樊
47
2026-09-23 10:29:22
栏目: 智能运维

在 Ubuntu 上启用 Apache2,一般步骤如下:

1. 安装 Apache2(如果还没装)

sudo apt update
sudo apt install apache2

2. 启动 Apache2 服务

sudo systemctl start apache2

3. 设置开机自启

sudo systemctl enable apache2

4. 检查运行状态

sudo systemctl status apache2

看到 active (running) 就说明已启用成功。

5. 配置防火墙(如有 UFW)

sudo ufw allow 'Apache Full'

或仅允许 HTTP:

sudo ufw allow 80

6. 验证访问

浏览器访问:

http://localhost

或服务器 IP,看到 Apache 默认页面即正常。


常用命令

  • 停止:sudo systemctl stop apache2
  • 重启:sudo systemctl restart apache2
  • 重载配置:sudo systemctl reload apache2

如果你是刚装好但访问不了,可以告诉我具体现象(如 403、连接拒绝等),我可以进一步帮你排查。

0 踩