Last active
May 1, 2017 18:42
-
-
Save sidcpatel/96f2609af8d19d1901efeb80f0f17a1c to your computer and use it in GitHub Desktop.
Generate nginx config file to skip cloudfront cidr addresses.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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