Ubuntu Apache的安全防护可以通过以下步骤进行:
sudo apt update && sudo apt upgrade
ServerSignature
和 ServerTokens
指令,隐藏服务器的版本信息和操作系统信息。ServerTokens Prod
ServerSignature Off
<Directory /var/www/html>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
sudo a2dismod php7.x_module
ufw
(Uncomplicated Firewall)管理防火墙规则,只允许必要的端口和服务通过。sudo apt install ufw
sudo ufw enable
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
<Directory /var/www/html>
Require all granted
</Directory>
sudo tail -f /var/log/apache2/access.log
sudo apt-get install logwatch
sudo cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf
sudo logwatch
mod_security
模块,对请求进行实时检查,防止SQL注入、跨站脚本攻击等。sudo apt-get install libapache2-mod-security2
sudo apt-get install apparmor apparmor-utils
sudo aa-enforce /etc/apparmor.d/usr.sbin.apache2
sudo tar -czvf /backup/apache_backup_(date %Y%m%d).tar.gz /var/www/html
通过上述步骤,可以显著提高Ubuntu系统上Apache服务器的安全性。