我为我的应用设置了gem rack-attack
。我想开始基于IP限制基本身份验证。
我的基本身份验证代码设置如下:
# config/environments/production.rb
config.middleware.insert_after(::Rack::Lock, '::Rack::Auth::Basic', ENV['RAILS_ENV') do |u, p|
[u, p] == [ENV['BASIC_AUTH_USERNAME'], ENV['BASIC_AUTH_PASSWORD']]
end
我想我的机架攻击会包含这样的内容:
# config/initializers/rack_attack.rb
Rack::Attack.throttle('req/ip', limit: 2, period: 60.seconds) do |req| req.ip
# what should belong here???
end