Skip to content

Set X-Forwarded-For header to original client IP when using Cloudflare in proxy mode

License

Notifications You must be signed in to change notification settings

ms-digital-labs/rack-cloudflare_ip

Repository files navigation

Rack::CloudflareIp

Overwrites the X_FORWARDED_FOR HTTP header with the contents of CF_CONNECTING_IP if it's present. This makes request.remote_ip in Rails return the IP of the user making the request rather than the IP of a Cloudflare server.

Installation

Add this line to your application's Gemfile:

gem 'rack-cloudflare_ip'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-cloudflare_ip

Usage

In config/application.rb:

require "rack/cloudflare_ip"
config.middleware.use Rack::CloudflareIp

Contributing

  1. Fork it ( http://github.com/ms-digital-labs/rack-cloudflare_ip/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Set X-Forwarded-For header to original client IP when using Cloudflare in proxy mode

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages