你提到的“修复 Debian Apache 日志”,可能有几种不同情况。下面我按常见场景分别说明,你可以对号入座。
systemctl status apache2
如果没运行:
sudo systemctl start apache2
编辑 Apache 配置:
sudo nano /etc/apache2/apache2.conf
# 或
sudo nano /etc/apache2/sites-enabled/000-default.conf
确认有以下内容:
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
查看变量值:
grep APACHE_LOG_DIR /etc/apache2/envvars
一般是:
/var/log/apache2
ls -ld /var/log/apache2
应该是:
drwxr-x--- www-data adm
如果权限坏了,修复:
sudo chown -R root:adm /var/log/apache2
sudo chmod 750 /var/log/apache2
sudo systemctl restart apache2
Apache 不会自动重建被删的日志,需要重启:
sudo touch /var/log/apache2/access.log
sudo touch /var/log/apache2/error.log
sudo chown www-data:adm /var/log/apache2/*.log
sudo systemctl restart apache2
测试配置:
sudo apache2ctl configtest
如果有错误,按提示修复。
Debian 默认用 logrotate:
sudo logrotate -d /etc/logrotate.d/apache2
强制执行:
sudo logrotate -f /etc/logrotate.d/apache2
Debian 默认用 AppArmor:
sudo aa-status | grep apache
如有异常可重启:
sudo systemctl restart apparmor
systemctl status apache2
apache2ctl configtest
ls -l /var/log/apache2
tail -n 50 /var/log/apache2/error.log
如果你能具体说一下:
apache2 -v)我可以给你更精确的修复命令。