详细说明:针对特定攻击的防御
2025-04-14
5
参考资料
DDoS攻击防御
配置速率限制:
limit_req_zone $binary_remote_addr zone=req_limit:10m rate=10r/s; limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
启用SYN Cookie防护
HTTP Flood防护
限制单个IP连接数:
limit_conn conn_limit 5; limit_req zone=req_limit burst=20;
慢速攻击防护
配置超时参数:
client_body_timeout 10s; client_header_timeout 10s; keepalive_timeout 5 5;
恶意扫描防护
屏蔽扫描工具User-Agent:
if ($http_user_agent ~* (nmap|sqlmap|wget|curl|nikto)) { return 403; }
目录遍历防护
禁用目录列表:
autoindex off;
SSRF防护
限制访问内网:
location ~* ^/(internal|admin) { deny 192.168.0.0/16; deny 10.0.0.0/8; allow all; }
配置错误利用防护
隐藏版本信息:
server_tokens off;
WebShell防护
限制PHP文件执行目录:
location ~* \.php$ { fastcgi_pass unix:/var/run/php-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; allow 192.168.1.0/24; deny all; }
实际案例配置
http { # 基础防护 server_tokens off; autoindex off; # 连接限制 limit_conn_zone $binary_remote_addr zone=conn_limit:10m; limit_req_zone $binary_remote_addr zone=req_limit:10m rate=10r/s; server { # 请求限制 limit_conn conn_limit 5; limit_req zone=req_limit burst=20 nodelay; # 超时设置 client_body_timeout 10s; client_header_timeout 10s; # 扫描防护 if ($http_user_agent ~* (nmap|sqlmap)) { return 444; } # 敏感目录防护 location /admin { allow 192.168.1.100; deny all; } } }
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。