Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active July 22, 2022 10:58
Show Gist options
  • Save sanmai/904a1f70b59ede519280 to your computer and use it in GitHub Desktop.
Save sanmai/904a1f70b59ede519280 to your computer and use it in GitHub Desktop.
Proxy GET requests to arbitrary hosts with nginx and secure_link
#$ URI=www.google.com/images/errors/robot.png
#$ SECRET=secret
#$ echo -n $URI$SECRET | md5sum
#649465bd9b4c3cf30ed8a24a89dbd203 -
#$ curl -sI http://proxy.example.net/proxy/$(echo -n $URI$SECRET | md5sum | sed 's/[^0-9a-f]//g')/$URI | grep Content-Length:
#Content-Length: 6327
server {
server_name proxy.example.net;
listen [::]:80;
resolver 127.0.0.1;
location /proxy {
expires max;
limit_except GET {
deny all;
}
secure_link_secret secret;
if ($secure_link = "") {
return 403;
}
if ($secure_link ~ "([^/]+)(/.+)") {
set $next_host $1;
set $next_uri $2;
}
#proxy_cache cache;
#proxy_cache_key "proxy:$next_host$next_uri";
#proxy_cache_valid 1h;
proxy_set_header Host $next_host;
proxy_pass http://$next_host$next_uri?;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment