Skip to content

Instantly share code, notes, and snippets.

@sidcpatel
Last active May 1, 2017 18:42
Show Gist options
  • Save sidcpatel/96f2609af8d19d1901efeb80f0f17a1c to your computer and use it in GitHub Desktop.
Save sidcpatel/96f2609af8d19d1901efeb80f0f17a1c to your computer and use it in GitHub Desktop.
Generate nginx config file to skip cloudfront cidr addresses.
#!/usr/bin/env ruby
require 'net/http'
require 'json'
url = URI.parse('https://ip-ranges.amazonaws.com/ip-ranges.json')
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
http.request(req)
end
json = JSON.parse(res.body)
print '# Amazon CloudFront IP Ranges'
print "# Generated at #{json['createDate']}"
json['prefixes'].select { |x| x['service'] == 'CLOUDFRONT' }.each do |y|
puts "set_real_ip_from #{y['ip_prefix']};"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment