在 Ubuntu 上“开启 Apache2”通常包含 安装、启动、设置开机自启、以及确认访问 几个步骤。下面按常见情况说明:
sudo apt update
sudo apt install apache2
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
看到 active (running) 就说明已经开启成功。
sudo ufw allow 'Apache'
# 或
sudo ufw allow 80/tcp
然后检查:
sudo ufw status
在浏览器中输入:
http://localhost
或服务器 IP:
http://你的服务器IP
看到 Apache2 Ubuntu Default Page 就成功了。
sudo systemctl stop apache2 # 停止
sudo systemctl restart apache2 # 重启
sudo systemctl reload apache2 # 重新加载配置
sudo netstat -tunlp | grep :80
默认目录:
/var/www/html
把 index.html 放这里即可。
如果你是指:
可以告诉我具体场景,我可以给你更针对性的配置。