43
37

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails ip制限をかける

Posted at

はじめに

セキュリティ的に特定ipからしかアクセスを受け付けたくなかったので、その対応メモ。

ip制限

application_controller.rb
before_action :restrict_remote_ip

  PERMIT_ADDRESSES = ['127.0.0.1', '::1', '000.000.00.00'].freeze

  def restrict_remote_ip
    unless PERMIT_ADDRESSES.include?(request.remote_ip)
      render text: 'Service Unavailable', status: 503
    end
  end

remote_ip()
http://api.rubyonrails.org/

43
37
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
37

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?