问题
我试图configurationfail2ban来使用这里显示的块来阻止ddos攻击。
基本上它会查看所有请求,如果任何单个IP在60秒内发出超过240个请求,则会阻止它们两天。
但是,我的nginx访问中的所有日志都来自127.0.0.1,这使得整个事情毫无意义。
什么可能导致nginxlogging来自服务器的所有stream量?
(我使用perusio的nginxconfiguration在LEMP堆栈上运行Drupal。)
既然你在nginx前面有清漆,它认为所有的请求都来自127.0.0.1,因为在技术上它们是。
为了解决这个问题,使用nginx真正的IP模块从X-Forwarded-For头中select客户端的IP地址,这个Varnish自动添加到请求中(除非你不告诉它)。
一个nginxconfiguration的例子是:
set_real_ip_from 127.0.0.1; real_ip_header X-Forwarded-For;
如果您使用Perusio的configuration,Micheal正在讨论的configuration示例片段位于/etc/nginx/nginx.conf的顶级nginxconfiguration中。
http { ## MIME types. include /etc/nginx/mime.types; default_type application/octet-stream; ## FastCGI. include /etc/nginx/fastcgi.conf; ## Default log and error files. access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## Use sendfile() syscall to speed up I/O operations and speed up ## static file serving. sendfile on; ## Handling of IPs in proxied and load balancing situations. set_real_ip_from 0.0.0.0/32; # all addresses get a real IP. real_ip_header X-Forwarded-For; # the ip is forwarded from the load balancer/proxy
您需要将0.0.0.0/32更改为127.0.0.1。