在 Ubuntu 上启用 Apache(通常是 Apache2)一般包含:安装 → 启动 → 设置开机自启 → 配置防火墙(可选)。下面按步骤说明。
sudo apt update
sudo apt install apache2 -y
sudo systemctl start apache2
检查状态:
sudo systemctl status apache2
看到 active (running) 表示成功。
sudo systemctl enable apache2
(如要取消自启:sudo systemctl disable apache2)
浏览器访问:
http://localhost
或服务器 IP:
http://你的服务器IP
看到 Apache2 Ubuntu Default Page 即成功。
sudo ufw allow 'Apache'
# 或
sudo ufw allow 80/tcp
查看状态:
sudo ufw status
sudo systemctl stop apache2 # 停止
sudo systemctl restart apache2 # 重启
sudo systemctl reload apache2 # 重载配置
/var/www/html
/etc/apache2/sites-available
/etc/apache2/sites-enabled
启用站点示例:
sudo a2ensite 你的配置名.conf
sudo systemctl reload apache2
如果你是想 启用 HTTPS / 虚拟主机 / PHP / 反向代理,可以告诉我具体需求,我可以给你针对性的配置示例。