当重定向URL的值使用encodeURIComponent编码时,Nginx不会重定向。
location /redirect/ {
return 307 $arg_target_url;
}当我从浏览器中输入url时:
mylocalserver.com/redirect/?target_url=example.com%3Fx%3Dy%26z%3Dk它被重定向到
mylocalserver.com/redirect/example.com%3Fx%3Dy%26z%3Dk期望是,应该将其重定向到url example.com?x=y&z=k。
但是,当$arg_target_url包含普通值时,它会工作。
发布于 2021-01-07 16:13:35
安装nginx和njs脚本语言,请阅读安装说明:nginx: Linux包。确保首先备份配置。
从Debian上的nginx稳定存储库安装nginx-module-njs和D2包的最小步骤如下:
echo "deb http://nginx.org/packages/debian $(lsb_release -cs) nginx" |
sudo tee /etc/apt/sources.list.d/nginx.list
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
sudo apt update
sudo apt install nginx nginx-module-njsnginx.conf)中。http.js,内容如下:函数decoded_target_url(r) {返回decodeURIComponent(r.args.target_url);}导出默认的{decoded_target_url};nginx -t检查配置并重新启动服务器。您需要将协议(http://或https://)添加到查询参数中。
mylocalserver.com/redirect/?target_url=http%3A%2F%2Fexample.com%2F%3Fx%3Dy%26z%3Dk或改变
return 307 $decoded_target_url 硬编码
return 307 http://$decoded_target_url或
return 307 https://$decoded_target_url相关文件:
https://unix.stackexchange.com/questions/627964
复制相似问题