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:
location = /myurl { 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
ngx.redirect(output, 301)