无法使nginx匹配路径的一部分

问题描述 投票:0回答:1

我有在docker-compose设置中运行的nginx,我想实现以下目标:

每个包含/something/的网址都传递给应用程序1每个包含/something/alsothis/的URL都传递给应用程序2

我当前的配置有:

location ~* ^/something/(?<path>.+) {
            proxy_pass http://app1/$path;
        }

location ~* ^/something/alsothis/(?<path>.+) {
            proxy_pass http://app2/$path;
        }

当我尝试https://www.example.com/something/rest_of_path时,它工作正常。

但是,当我尝试https://www.example.com/something/alsothis/rest_of_path时,在邮递员中出现了Unkown错误(nginx中记录了500错误)。

另外,我再次检查了app2是否正常工作。当我将第一个位置更改为app2时,它也可以正常工作。

似乎无法弄清楚出了什么问题,非常感谢所有帮助。

提前感谢!

nginx nginx-reverse-proxy nginx-location
1个回答
0
投票

理查德是对的,只需要更改顺序。

© www.soinside.com 2019 - 2024. All rights reserved.