在 Ubuntu 上,Apache 的配置文件主要位于 /etc/apache2/ 目录下。下面是常见的配置位置和说明:
/etc/apache2/
| 路径 | 说明 |
|---|---|
/etc/apache2/apache2.conf |
主配置文件(全局配置) |
/etc/apache2/ports.conf |
监听端口(如 80、443) |
/etc/apache2/sites-available/ |
可用站点配置文件(虚拟主机) |
/etc/apache2/sites-enabled/ |
已启用站点(软链接) |
/etc/apache2/mods-available/ |
可用模块 |
/etc/apache2/mods-enabled/ |
已启用模块 |
/etc/apache2/conf-available/ |
额外配置 |
/etc/apache2/conf-enabled/ |
已启用配置 |
sudo nano /etc/apache2/sites-available/example.conf
示例:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
AllowOverride All
</Directory>
</VirtualHost>
sudo a2ensite example.conf
sudo systemctl reload apache2
sudo a2dissite example.conf
# 启动
sudo systemctl start apache2
# 停止
sudo systemctl stop apache2
# 重启
sudo systemctl restart apache2
# 重载配置
sudo systemctl reload apache2
# 查看状态
sudo systemctl status apache2
默认网站目录:
/var/www/html
sudo a2enmod rewrite
sudo systemctl restart apache2
如果你是 配置 HTTPS、PHP、反向代理、或者多个网站,可以告诉我具体需求,我可以直接给你完整配置示例。