nginx正则表达式位置

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

我们需要通过nginx提供静态内容。以下是我们的位置指令:

location ~ /app$ {
        root   /srv/deployments/app/build/;
        index  index.html;
    }

现在,我们期望/ app / login,/ app / signup之类的任何东西都将由该location指令提供服务。但是当我们尝试访问/ app / login时,我们出现[[404错误。除了上面的位置指令以外,如果我们在下面的位置指令中定义,那么它也可以工作。

location ~ /app/login$ { root /srv/deployments/app/build/; index index.html; }
由于可能有多个路由,我们如何使用正则表达式定义位置指令,以便与/app/.*匹配的任何位置都应由单个位置提供。
nginx nginx-location
1个回答
0
投票
请检查此link是否有帮助。

建议

location ~ ^/sitename/[0-9a-z]+/index.php$ { fastcgi_pass phpcgi; }

其中:

^->字符串开头

[[0-9a-z] +->匹配此范围内的所有字符

index.php $->带有index.php的字符串结尾

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