nginx redirect to output of command
You can use the lua plugin (sudo apt -y install libnginx-mod-http-lua
) in order to use this technique to redirect to an URL that is the output of a command line command:
example-2.txt
access_by_lua_block {
local process = io.popen("curl -fsSL http://mydomain.com/file-which-contains-an-URL.txt", "r")
local output = process:read('*a')
process:close()
ngx.redirect(output)
}
}
By default, this redirects using the status code 302
(temporary redirect - not cached). In case you want a 301
(moved permanently) instead, use
example-1.txt
Check out similar posts by category:
Nginx
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow