Ubuntu 上重装 Apache2 的安全做法
一 准备与备份
ls /etc/apache2/sites-enabled/ls /etc/apache2/mods-enabled/apache2ctl -v、systemctl status apache2二 标准重装步骤(保留数据与配置)
sudo apt updatesudo apt install --reinstall apache2sudo systemctl restart apache2sudo systemctl enable apache2sudo apache2ctl configtestsudo systemctl status apache2三 完全重装(清配置与网站目录后重装)
sudo systemctl stop apache2sudo apt purge apache2 apache2-utils apache2.2-common -ysudo apt autoremove -ysudo rm -rf /etc/apache2 /var/wwwsudo apt updatesudo apt install apache2 -ysudo systemctl start apache2sudo systemctl enable apache2apache2ctl -vsudo systemctl status apache2四 重装后的快速恢复
sudo a2ensite 站点名.conf 启用,然后 sudo systemctl reload apache2。sudo a2enmod 模块名 启用,然后 sudo systemctl reload apache2。sudo apache2ctl configtest && sudo systemctl reload apache2,访问测试确认业务恢复。五 常见问题与排查
sudo apache2ctl configtest 定位错误行并修正,再 reload。sudo systemctl status apache2、sudo tail -f /var/log/apache2/error.log,按日志提示修复。