如何阻止或过滤Heroku上的IP地址? [英] How can you block or filter IP addresses on Heroku?

查看:167
本文介绍了如何阻止或过滤Heroku上的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以实现IP过滤或IP访问规则,就像我用nginx / apache限制或阻止Heroku上的某些IP一样?

注意:我知道这可以很容易地从我的应用程序(Rails 3.2)中完成,但我不认为这是Heroku上我的资源的最高效使用。另外,基于Rack的解决方案比在Rails中实现过滤要好。

//github.com/udzura/rack-blockrel =noreferrer>'rack-block'作为Rack中间件。在config / initializers中,添加一个新文件:

  YourApp :: Application.configure do 

config .middleware.insert_before(Rack :: Lock,Rack :: Block)做
#在这里添加机架语法的规则
end

end

就像一个魅力一样。


Is there a way to implement IP filtering or IP access rules much like I would with nginx/apache to restrict or block certain IPs on Heroku?

Note: I know this can be done from within my application (Rails 3.2) very easily but I don't think this is the most efficient use of my resources on Heroku. Also, a Rack based solution would be better than implementing the filtering in Rails.

解决方案

I added 'rack-block' as Rack middleware. In config/initializers, add a new file:

YourApp::Application.configure do

  config.middleware.insert_before(Rack::Lock, Rack::Block) do  
    # Add your rules with the rack-block syntax in here
  end

end

Works like a charm.

这篇关于如何阻止或过滤Heroku上的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆