以下是在Ubuntu Apache中配置安全策略的關鍵步驟:
系統更新與軟件包管理
定期更新系統和Apache軟件包,修復安全漏洞:
sudo apt update && sudo apt upgrade
隱藏敏感信息
修改Apache配置文件(/etc/apache2/apache2.conf
),隱藏版本信息和默認頁面:
ServerTokens Prod
ServerSignature Off
禁用不必要的模塊
禁用未使用的模塊(如mod_php
等),減少攻擊面:
sudo a2dismod 模塊名
配置防火墻(UFW)
允許HTTP(80)和HTTPS(443)流量,拒絕其他非法訪問:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
啟用SSL/TLS加密
安裝證書并配置虛擬主機,強制使用HTTPS:
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
安全模塊配置
sudo apt install libapache2-mod-security2
sudo a2enmod security2
訪問控制與權限管理
Require ip
限制特定IP訪問敏感目錄。<Directory "/var/www/html">
Options -Indexes
</Directory>
日志記錄與監控
啟用詳細日志記錄,定期分析異常行為:
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
定期備份與安全審計
備份配置文件和網站數據,定期掃描漏洞。
參考來源:[1,2,3,4,5,6,7,8,9,10,11]