开发者

How can you add IP restrictions to your rails app?

开发者 https://www.devze.com 2023-03-29 01:34 出处:网络
Is there a way to add IP restrictions to the rails app. Som开发者_开发技巧e type of rack middleware so only the set list of IPs can access the rails app for security reasons?

Is there a way to add IP restrictions to the rails app. Som开发者_开发技巧e type of rack middleware so only the set list of IPs can access the rails app for security reasons?

Thanks


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


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

精彩评论

暂无评论...
验证码 换一张
取 消