How can you add IP restrictions to your rails app?

前端 未结 2 859
遇见更好的自我
遇见更好的自我 2021-01-23 15:22

Is there a way to add IP restrictions to the rails app. Some type of rack middleware so only the set list of IPs can access the rails app for security reasons?

Thanks

相关标签:
2条回答
  • 2021-01-23 15:51

    You can add a before_filter in the application controller and check the request IP,and redirect it to a no-access page.

    if request.remote_ip !~ /^XXX\.YYY\.ZZZ\./
      redirect_to no_access_url
      return false
    end
    
    0 讨论(0)
  • 2021-01-23 16:05

    Use a routing constraint as described here: http://guides.rubyonrails.org/routing.html#advanced-constraints.

    0 讨论(0)
提交回复
热议问题