在Ubuntu LNMP(Linux, Nginx, MySQL, PHP)环境下,防止DDoS攻击可以通过以下几种方法来实现:
sudo ufw enable
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp   # SSH
sudo ufw allow 80/tcp   # HTTP
sudo ufw allow 443/tcp  # HTTPS
http {
    limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s;
    server {
        listen 80;
        server_name example.com;
        location / {
            limit_req zone=mylimit burst=5 nodelay;
            ...
        }
    }
}
sudo apt-get install fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local
jail.local中添加以下内容:[nginx]
enabled = true
port = http,https
filter = nginx-badbots
logpath = /var/log/nginx/access.log
maxretry = 3
bantime = 600
SET GLOBAL max_connections = 100;
SET GLOBAL query_cache_size = 0;
SET GLOBAL query_cache_type = 0;
sudo apt-get install libapache2-mod-security2
sudo systemctl enable apache2-mod-security2
sudo systemctl start apache2-mod-security2
sudo apt update
sudo apt upgrade
通过以上方法,可以有效地提高Ubuntu LNMP环境对DDoS攻击的防御能力。记住,网络安全是一个持续的过程,需要不断评估和改进防御措施。