在Linode.com上设置nodebalancer后,IP欺骗攻击错误

我最近在Rails 3.2.12应用程序前面设置了一个NodeBalancer。 该应用程序由nginx独angular兽服务。

所有似乎都很好,但我得到了很多错误,如我只有一台服务器时没有得到的错误。

IP spoofing attack?!HTTP_CLIENT_IP="10.16.81.184"HTTP_X_FORWARDED_FOR="136.160.88.153, 192.168.255.5" actionpack (3.2.12) lib/action_dispatch/middleware/remote_ip.rb:55:in `calculate_ip' 

这是我的应用程序的nginxconfiguration。

 upstream unicorn { server unix:/tmp/unicorn.ahotu-calendars.sock fail_timeout=0; } server { listen 80 default deferred; root /home/deployer/apps/appdirectory/current/public; if (-f $document_root/system/maintenance.html) { return 503; } error_page 503 @maintenance; location @maintenance { rewrite ^(.*)$ /system/maintenance.html last; break; } location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } 

我在configuration文件中做错了什么?

谢谢。

为了防止客户伪造代理头, X-Forwarded-ForClient-Ip必须等于不引起这种错误。

只需在你的nginxconfiguration中设置Client-Ip头:

至于你的日志中的IP地址:

  • 192.168.255.5可能是NodeBalancer的内部IP
    (Linode Library中的示例像往常一样显示192.168.0.0/16子网;应该是静态的 – 或者至less保留在子网内)
  • 136.160.88.153是你想知道的真正的远程地址
  • 10.16.81.184是一些其他未知的IP地址 – 也许另一个代理join它更早
    (它是否出现在每个请求或有时是空的?)

对不起,我不知何故相信(你的) nginx会在NodeBalancer上运行。
像这样使用HttpRealIpModule

 # trust connections from internal addresses set_real_ip_from 192.168.0.0/16; real_ip_header X-Forwarded-For; 

或者,至less确保将原始的X-Forwarded-For头部传递给Rails,而不是nginx的修改后的头部,并且取消设置Client-Ip (无论它来自哪里):

 proxy_set_header X-Forwarded-For $http_x_forwarded_for; proxy_set_header Client-Ip "";