首页 > 解决方案 > Nginx 位置重定向

问题描述

如果你愿意,伙计们,帮我解决这个问题我想要访问这个 URL https://123.com/storage/app/profiles/Ar.BB_1585493889.png?w=200&h=200

用最后的参数 w= 和 h= 做一个代理传递给他只有当 URL 关联两个参数 w= 和 h= 时。我试图这样做,但它不起作用

> $1 = for the file name which is Ar.BB_1585493889.png
> $2 = for width(w=) 
> $3 = for height (h=)


location ~* ^/storage/app/profiles/(.*)?w\=(.*)\&h\=(.*) {
proxy_pass http:/123.com:8888/unsafe/$2x$3/smart/https://123.com/storage/app/profiles/$1;
}

非常感谢您的帮助。

标签: nginxnginx-reverse-proxynginx-location

解决方案


与我的同事一起工作,他解决了其中的难题,我发现了代理传递的解决方案,这完全是关于通过代理将拇指图像重定向到 Nginx,因此移动团队不必更改任何 URL。

        location ~* ^/storage/app/profiles/(.*) {
#error_page   400 401 402 403 404 405 500 501 502 503 504  @error_page;
                set $image $1;
                if ($is_args = "?") {
                        rewrite ^.*$ "/unsafe/${arg_w}x${arg_h}/smart/https://123.com/storage/app/profiles/$image?" break;
                        proxy_pass http://127.0.0.1:8888;

                }
        }

如果 Thumbor 服务器不工作,您仍然可以使用 error_page 将人们重定向到真实的 url。


推荐阅读