view raw
Pedro Romano Pedro Romano - 7 months ago 48
Apache Configuration Question

Finding the closest Apache Software Foundation mirror programatically

For my deployment automation needs, I would like to dynamically and programatically determine the closest Apache Software Foundation mirror since the servers are distributed across geographically distinct locations and it would be ideal to dynamically determine the best mirror without having to hard-code that knowledge somewhere.

The only approach I could think of so far is to scrap the page for the closest mirror suggested there, but it seems a bit cumbersome and fragile.

Is there a web API endpoint that provides this functionality in a stable and reliable way?

Joe Joe

The mirror URLs in the page are marked up as <strong>, so you can scrape the page to get the top recommendation like this:

curl '' |
  grep -o '<strong>[^<]*</strong>' |
  sed 's/<[^>]*>//g' |
  head -1

Additionally, closer.cgi supports an ?as_json=1 query parameter to provide the same information as JSON. The result has a key of preferred for the closest mirror, as well as http for the alternatives.