How can you block or filter IP addresses on Heroku?

前端 未结 2 939
抹茶落季
抹茶落季 2020-12-29 04:52

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

相关标签:
2条回答
  • 2020-12-29 05:19

    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.

    0 讨论(0)
  • 2020-12-29 05:33

    You should check out rack-attack. Looks like it does the same as rack-block, but is much more widely used and updated frequently. To block a specific IP you can do this:

    # Block requests from 1.2.3.4
    Rack::Attack.blacklist('block 1.2.3.4') do |req|
      # Requests are blocked if the return value is truthy
      '1.2.3.4' == req.ip
    end
    
    0 讨论(0)
提交回复
热议问题