![NGINX 在 DDoS 攻擊期間沒有回應](https://rvso.com/image/668051/NGINX%20%E5%9C%A8%20DDoS%20%E6%94%BB%E6%93%8A%E6%9C%9F%E9%96%93%E6%B2%92%E6%9C%89%E5%9B%9E%E6%87%89.png)
我直接開門見山,NGINX 似乎在使用 XML-RPC 的 DDoS 攻擊期間不處理任何 HTTP 請求。
在 XML-RPC DDoS 攻擊期間,伺服器僅使用約 1% 的 CPU。
伺服器使用 12 個核心,NGINX 設定為使用 12 個工作進程。
這是我目前的配置
nginx.conf:
user nginx;
worker_processes 12;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 12288;
}
http {
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
limit_conn_zone $binary_remote_addr zone=one:10m;
limit_req_zone $binary_remote_addr zone=two:10m rate=5r/s;
sendfile on;
#tcp_nopush on;
keepalive_timeout 30;
server_tokens off;
include /etc/nginx/conf.d/*;
}
預設.conf:
server {
listen 80 default_server;
server_name _;
include /etc/nginx/default.d/*.conf;
limit_conn one 10;
limit_req zone=two burst=10 nodelay;
if ($http_user_agent ~* (wordpress))
{
return 444;
}
if ($http_user_agent = "")
{
return 444;
}
client_body_buffer_size 1K;
client_header_buffer_size 1k;
client_max_body_size 1k;
large_client_header_buffers 2 1k;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;
access_log off;
location / {
root /var/www/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
root /var/www/html;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /status/ {
stub_status on;
}
}
sysctl.conf:
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.tcp_syncookies = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
我並不打算將攻擊阻止到 NGINX 甚至無法接收請求的程度,我只是希望在攻擊期間保持 NGINX 運行以監控每秒的請求。
非常感謝。
答案1
這就是DDos攻擊的重點,就是徹底耗盡所有資源。沒有什麼神奇的配置可以讓人說設定這個選項並且 nginx 會回應。您必須阻止入站流量。
然後,如果您阻止網路伺服器上的入站流量,那麼可能發生的情況是您的下游會飽和到真正的請求無法通過的程度。因此,您需要使用上行鏈路來阻止它們。