Debian LAMP安全配置主要包括以下方面:
系统与软件更新
定期更新系统和软件包,修复安全漏洞:
sudo apt update && sudo apt upgrade -y
。
防火墙配置
使用UFW限制端口访问,仅允许HTTP(80)、HTTPS(443)、SSH(22)等必要端口:
sudo ufw enable && sudo ufw allow 80/tcp && sudo ufw allow 443/tcp && sudo ufw allow 22/tcp
。
Apache安全设置
autoindex
):sudo a2dismod autoindex
。ServerTokens Prod
和ServerSignature Off
。Options -Indexes
。sudo apt install certbot python3-certbot-apache && sudo certbot --apache
。数据库安全加固
bind-address=127.0.0.1
。DELETE FROM mysql.user WHERE User=''
,DROP DATABASE IF EXISTS test
。CREATE USER 'app_user'@'localhost' IDENTIFIED BY '密码'
。PHP安全配置
exec
、system
):disable_functions = exec,passthru
。open_basedir=/var/www:/tmp
,禁止远程文件包含:allow_url_fopen=Off
。display_errors=Off
,log_errors=On
。用户与权限管理
/etc/ssh/sshd_config
中PermitRootLogin no
。日志与监控
tail -f /var/log/apache2/access.log
。其他安全措施
sudo tar -czvf /backup/backup-$(date +%F).tar.gz /var/www/html
。PasswordAuthentication no
。参考来源:[1,2,3,5,6,7,8,9,10,11,12,13,14]