下面以 Debian(含 Debian 11/12 等常见版本) 为例,说明如何安装和配置 Apache2。
sudo apt update
sudo apt upgrade -y
sudo apt install apache2 -y
安装完成后,Apache 会自动:
/etc/apache2 配置目录sudo systemctl status apache2
如果看到 active (running) 说明已正常运行。
启动 / 停止 / 重启命令:
sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
sudo systemctl enable apache2
如果你使用 ufw:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
在浏览器中访问:
http://服务器IP
或本地:
http://localhost
看到 Apache2 Debian Default Page 即成功。
/var/www/html
/etc/apache2/apache2.conf
/etc/apache2/sites-available/
/etc/apache2/sites-enabled/
检查是否有其他 Web 服务(如 nginx):
sudo netstat -tulnp | grep :80
sudo apache2ctl configtest
sudo systemctl restart apache2
如果你需要:
可以继续告诉我你的使用场景。