我们的 rails 应用被大量使用 IP 地址的机器人发出的请求淹没。每个请求都会导致出现异常通知错误消息。
我们原来的 Nginx 服务器块:
server {
server_name example.com www.example.com *.example.com;
passenger_enabled on;
rails_env production;
root /home/deploy/cm/public;
passenger_app_root /home/deploy/cm;
passenger_friendly_error_pages on;
index index.html index.htm;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name example.com www.example.com *.example.com;
return 404; # managed by Certbot
}
我将 444.html 文件放在公共目录中,并将其添加到我们的 Nginx 服务器块的顶部:
server {
listen 80;
server_name _;
return 444;
}
这不会导致错误消息数量发生变化。错误消息包括:
* SERVER_PORT : 443
* SERVER_PROTOCOL : HTTP/1.1
* SERVER_SOFTWARE : nginx/1.18.0 Phusion_Passenger/6.0.6
如果有人使用 IP 地址而不是我们的域名,我该如何修改服务器块以返回 444?
答案1
将其放在配置的顶部:
server {
listen 80 default_server;
return 444;
}