以下是CentOS Apache2常見問題的解決方法:
啟動失敗
sudo systemctl status httpd
。sudo tail -n 50 /var/log/httpd/error_log
。sudo netstat -tuln | grep 80
,修改httpd.conf
中Listen
端口。sudo apachectl configtest
。403錯誤
sudo chmod -R 755 /path/to/website
,sudo chown -R apache:apache /path/to/website
。.htaccess
配置正確,或暫時禁用.htaccess
測試。端口沖突
sudo netstat -tuln | grep :80
查找占用端口的進程,終止或修改Apache監聽端口。權限問題
apache
)對文件/目錄有讀寫權限:sudo chown -R apache:apache /var/www/html
。防火墻/SELinux限制
sudo firewall-cmd --add-service=http --permanent
,sudo firewall-cmd --reload
。sudo setenforce 0
,若需永久修改需編輯/etc/selinux/config
。模塊加載失敗
ls /usr/lib64/httpd/modules/
,確保配置文件中正確加載模塊。訪問速度慢
httpd.conf
添加mod_deflate
和mod_cache
配置。提示:操作前建議備份配置文件,若無法解決可查看錯誤日志獲取具體錯誤信息。