Nginx Lua ProxyPass

events {
worker_connections 1024;
}http
{
server {
# ENABLE 443 and its config when doing actual prod deployment
listen 8081;
location /proxy {
resolver XX.XX.XX.XX;
proxy_pass $arg_source;
}
}
}
curl http://127.0.0.1:8081/proxy?source=https://mediacdn.espssl.com/9850/Shared/Perfumania/Template/perf-ship.jpg
curl http://127.0.0.1:8081/proxy?source=https%3A%2F%2Fmediacdn.espssl.com%2F9850%2FShared%2FPerfumania%2FTemplate%2Fperf-ship.jpg
invalid URL prefix in "https%3A%2F%2Fmediacdn.espssl.com%2F9850%2FShared%2FPerfumania%2FTemplate%2Fperf-ship.jpg", client: 127.0.0.1, server: localhost, request: "GET /?source=https%3A%2F%2Fmediacdn.espssl.com%2F9850%2FShared%2FPerfumania%2FTemplate%2Fperf-ship.jpg HTTP/1.1", host: "127.0.0.1:8081"
server {
listen 8081;
location /proxy {
resolver XX.XX.XX.xx;
set $proxy "";
rewrite_by_lua_block {
local myu = ngx.var.arg_source ;
ngx.var.proxy = ngx.unescape_uri(myu)
}
proxy_pass $proxy;
}
}
curl http://127.0.0.1:8081/proxy?source=https://mediacdn.espssl.com/9850/Shared/Perfumania/Template/perf-ship.jpg
curl http://127.0.0.1:8081/proxy?source=https%3A%2F%2Fmediacdn.espssl.com%2F9850%2FShared%2FPerfumania%2FTemplate%2Fperf-ship.jpg

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store