Ubuntu 上 Apache 报错的原因非常多,需要看具体报错信息才能准确判断。下面我先给你整理一下最常见的几类原因 + 排查方法,你可以对照看看。
典型报错
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
原因
排查
sudo netstat -tulnp | grep ':80'
sudo lsof -i:80
解决
sudo systemctl stop nginx
sudo systemctl restart apache2
典型报错
AH00526: Syntax error on line XX of /etc/apache2/...
排查
sudo apache2ctl configtest
常见错误
<VirtualHost> 写错</Directory>典型表现
403 Forbidden
正确权限
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
例如:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
解决
sudo a2enmod rewrite
sudo systemctl restart apache2
典型报错
AH02572: Failed to configure at least one certificate
检查
sudo apache2ctl configtest
常见原因
sudo systemctl status apache2
如果失败:
sudo journalctl -xeu apache2
请贴出以下信息之一,我可以精确帮你:
sudo journalctl -xeu apache2 的输出sudo apache2ctl configtest 的输出如果你愿意,可以直接把报错截图或文字发给我,我一步一步帮你修。