“Apache怎么配置”范围很广,下面我按最常见的使用场景,用 Apache HTTP Server(httpd) 给你一个实用配置指南,从安装到常见配置一步步来。
Ubuntu / Debian
sudo apt update
sudo apt install apache2
CentOS / Rocky / Alma
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd
/etc/apache2/
├── apache2.conf # 主配置
├── sites-available/ # 可用站点
├── sites-enabled/ # 启用的站点(软链接)
├── mods-available/
└── mods-enabled/
/etc/httpd/
├── conf/httpd.conf
└── conf.d/
# Ubuntu
sudo systemctl start apache2
sudo systemctl restart apache2
# CentOS
sudo systemctl restart httpd
www.example.comsudo mkdir -p /var/www/example.com/public_html
sudo chown -R $USER:$USER /var/www/example.com
Ubuntu
sudo nano /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example_error.log
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
sudo a2enmod rewrite
sudo systemctl restart apache2
.htaccess 示例:
RewriteEngine On
RewriteRule ^article/([0-9]+)$ article.php?id=$1
sudo a2enmod ssl
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
<Directory /var/www/example.com/public_html>
Options -Indexes
</Directory>
Listen 8080
<VirtualHost *:8080>
DocumentRoot /var/www/example.com/public_html
</VirtualHost>
# 检查配置是否正确
apachectl configtest
# 查看日志
tail -f /var/log/apache2/error.log
为了给你更精准的配置,你可以说:
我可以直接帮你写 完整可用配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。