简体   繁体   English

如何在Ruby on Rails中阻止特定的IP地址

[英]How do you block specific IP adress in Ruby on Rails

I am in charge of a few live websites made in Ruby on Rails. 我负责一些用Ruby on Rails制作的实时网站。 I have a few IP adresses that keep attacking these sites and I would like to block their IP adresses. 我有一些IP地址不断攻击这些网站,我想阻止他们的IP地址。 I know they can get around this wall with a proxy but I do wish to make it harder for them and would love to know where I need to set this up in my ruby on rails app. 我知道他们可以通过代理绕过这堵墙,但我确实希望让他们更难,并且很想知道我需要在我的ruby on rails app中设置它。 Thank you everyone! 谢谢大家!

class ApplicationController < ActionController::Base
  before_filter :block_ip_addresses

  protected

  def block_ip_addresses
    head :unauthorized if current_ip_address == "XX.XX.XX.XX"
  end

  def current_ip_address
    request.env['HTTP_X_REAL_IP'] || request.env['REMOTE_ADDR']
  end
end

Thanks to: https://stackoverflow.com/a/10895438/1466095 感谢: https//stackoverflow.com/a/10895438/1466095

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM