Skip to content

Instantly share code, notes, and snippets.

@radiofrequency
Created February 5, 2018 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save radiofrequency/3d582a118b8e9714898794e0afe94ddd to your computer and use it in GitHub Desktop.
Save radiofrequency/3d582a118b8e9714898794e0afe94ddd to your computer and use it in GitHub Desktop.
list cloufront ip ranges for nginx real ip module
var request = require("request");
var fs = require("fs");
var output = "#cloudfront ip ranges\n";
request("https://ip-ranges.amazonaws.com/ip-ranges.json", function(err, res, body) {
if (err) {
console.error("error", err);
}
var j = JSON.parse(body);
j.prefixes.forEach(function(item) {
if (item.service ==='CLOUDFRONT') {
output += "set_real_ip_from " + item.ip_prefix + ";\n"
}
})
fs.writeFileSync(__dirname + "/etc/cloudfront_ips", output);
console.log("write cloudfront ips");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment