Skip to content

Instantly share code, notes, and snippets.

@PascalLeMerrer
Last active February 18, 2021 17:30
Show Gist options
  • Save PascalLeMerrer/288b4ed9891b5b47ba97f78d3f62cdab to your computer and use it in GitHub Desktop.
Save PascalLeMerrer/288b4ed9891b5b47ba97f78d3f62cdab to your computer and use it in GitHub Desktop.

Goal: create a proxy forwarding requests to https://api.unsplash.com. The proxy adds Authorization and Accept-Version headers, to comply with the terms of use of the API.

First I create the rp.conf file with the content below.

Then I run nginx with:

docker run --rm -d -p 8080:8888 -v $PWD/rp.conf:/etc/nginx/nginx.conf nginx

To test the proxy:

curl -v 'http://localhost:8080/search/photos?query=mountain'

NB: it cannot pass through the non-transparent corporate proxy.

events { }
http {
server_names_hash_bucket_size 128;
access_log /dev/stdout;
error_log /dev/stderr;
server {
listen 8888;
location / {
proxy_pass https://api.unsplash.com;
proxy_ssl_server_name on;
proxy_set_header Host "api.unsplash.com";
proxy_set_header Authorization "Client-ID <MY OAUTH TOKEN>";
proxy_set_header Accept-Version "v1";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment