nginx 重定向到命令输出

你可以使用 lua 插件(sudo apt -y install libnginx-mod-http-lua)来使用此技术重定向到命令行命令输出的 URL:

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)
    }
}

默认情况下,这使用状态码 302(临时重定向 - 不缓存)重定向。如果你想要 301(永久移动),使用

example-1.txt

Check out similar posts by category: Nginx