Nginx正则表达式位置

时间:2020-05-25 07:00:00

标签: nginx nginx-location

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

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

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

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

由于可能有多条路线,我们如何使用regex定义位置指令,以便与/app/.*匹配的任何位置都应由单个位置提供服务。

1 个答案:

答案 0 :(得分:0)

请检查此GroupBy.transform是否有帮助。

建议(特定于该问题)

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

其中:

^->字符串开头

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

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