[转]Create Multiple IP Addresses to One Single Network Interface

https://www.tecmint.com/create-multiple-ip-addresses-to-one-single-network-interface/

Advertisements

Rails允许多个IP访问的设置办法

方法1

config/routes.rb

constraints(:ip => %r{#{Settings.ip.allow}}) do
 post '/somecontroller/callback', to: 'somecontroller#callback' , as: 'somecontroller_callback'
end

config/settings.yml

ip:
  allow: '127.0.0.1|127.0.0.2'

方法2

config/routes.rb

constraints(:ip => Settings.ip.allow) do
 post '/somecontroller/callback', to: 'somecontroller#callback' , as: 'somecontroller_callback'
end

config/settings.yml

ip:
  allow: !ruby/regexp /127.0.0.1|127.0.0.2/

方法3

before_filter :protect

def protect
  @ips = ['127.0.0.1', '127.0.0.2'] #And so on ...]
  if not @ips.include? request.remote_ip
     # Check for your subnet stuff here, for example
     # if not request.remote_ip.include?('127.0,0')
     render :text => "You are unauthorized"
     return
  end
end

Links