问题举例:
location 配置了 ^~/mobile
访问: http://yourdomain/mobile/ 正常;
访问: http://yourdomain/mobile 异常,nginx会进行重定向
当时配置如下:
在多次查询资料后得知导致此问题的根源是因为我们域名带有特殊端口,当访问ng时如果结尾没有/,ng会自动重定向到80或者443端口上去并在结尾附上/,这就导致上面的异常情况。如访问https://testdomain:8443/mobile,ng检测结尾没有/会将其自动重定向至https://testdomian/mobile/这样就会导致访问异常。
解决方法:
使用根路径进行匹配,判断具体的path,如果符合规则 手动重新进行一次转发
location / {
if ($request_uri ~* /mobile){
return 302 https://testdomian:8443$uri/?$args;
}
}
上述访问: https://testdomain:8443/mobile 会匹配到location /进行转发逻辑处理
然后完美解决