在 Ubuntu 上安装 Apache(通常指 Apache HTTP Server)非常简单,下面按步骤来:
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 Full'
或只开放 HTTP / HTTPS:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
在浏览器中访问:
http://服务器IP
看到 Apache2 Ubuntu Default Page 即成功。
/var/www/html/etc/apache2/apache2.conf/etc/apache2/sites-available//etc/apache2/sites-enabled//etc/apache2/mods-available/sudo systemctl restart apache2 # 重启
sudo systemctl reload apache2 # 平滑重载
sudo apache2ctl configtest # 检查配置语法
sudo nano /etc/apache2/sites-available/example.conf
内容示例:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
启用站点:
sudo a2ensite example.conf
sudo systemctl reload apache2
如果你需要 开启 HTTPS(SSL)、PHP 支持、反向代理 或 多站点配置,可以继续问我。