sudo apt update
sudo apt install --only-upgrade apache2 # 僅升級Apache2
# 或
sudo apt full-upgrade # 升級所有相關包
apt-cache policy apache2
查看可用版本,再執行:sudo apt install apache2=版本號
sudo systemctl restart apache2
apache2 -v # 終端查看
# 或訪問服務器IP/域名查看頁面信息
sudo apachectl configtest # 檢查配置文件語法
sudo tar -czvf apache_backup_$(date +%Y%m%d).tar.gz /etc/apache2 /var/www/html
/etc/apache2/apache2.conf
,設置ServerTokens Prod
和ServerSignature Off
。sudo a2dismod 模塊名
關閉非必需模塊。tail -f /var/log/apache2/error.log
注意:升級前務必備份重要數據,生產環境建議先在測試環境驗證。
參考來源: