---
title: Use Nginx Reverse Proxy to Mirror GitHub API
date: 2014-08-21T16:50:36+00:00
modified: 2025-11-28T00:15:33+00:00
permalink: https://kaspars.net/blog/use-nginx-reverse-proxy-mirror-github-api
post_type: post
author:
  name: Kaspars
  avatar: https://reverse.kaspars.net/gravatar/avatar/92bfcd3a8c3a21a033a6484d32c25a40b113ec6891f674336081513d5c98ef76?s=96&d=mm&r=g
category:
  - Development
post_tag:
  - How to
  - Nginx
  - Snippet
---

# Use Nginx Reverse Proxy to Mirror GitHub API

Everyone knows that GitHub is awesome and so is [their API](https://developer.github.com "GitHub API"). However, there [are limits](https://developer.github.com/v3/#rate-limiting) to the amount of unauthenticated request you can make to the API from a single IP address. I am using their API for automatic updates for all of [my GitHub hosted plugins](https://github.com/kasparsd/) with the [Git Update plugin](https://github.com/kasparsd/git-update) and it hit the limits really quick.

I decided to create **a reverse proxy** with generous level of caching to enable almost unlimited API requests where all request to:

```
https://github.example.com/kasparsd/...
```

(where `kasparsd` is my GitHub username) are being proxied to

```
https://api.github.com/repos/kasparsd/...
```

using the following Nginx config rules:

```
proxy_cache_path /var/cache/nginx-github  levels=1:2 keys_zone=github:10m;

server {
        server_name github.example.com;

        location /kasparsd/ {
                resolver 8.8.8.8;

                proxy_pass https://api.github.com/repos/kasparsd/;
                proxy_cache github;
                proxy_cache_valid 200 302 1h;
                proxy_ignore_headers Expires Cache-Control Set-Cookie X-Accel-Redirect X-Accel-Expires;
                proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;

                proxy_set_header User-Agent YOURGITHUBUSERNAME;
                proxy_set_header Authorization "token YOURTOKEN";
        }
}
```

Where `resolver` is the DNS server for resolving `proxy_pass` resource and all HTTP 200 and 302 responses are cached for an hour while forcing Nginx to ignore `Expires` and `Cache-Control` response headers to avoid skipping cache. [GitHub also suggests](https://developer.github.com/v3/auth/) sending optional `User-Agent` and `Authorization` headers.