Nginx正则表达式 pcre_compile() 失败

请问为什么以下条件会失败?好像最后一个 ) 被切断了。

    location / {
        if ($request_uri !~ "(abc|def)" {
            return 404;
        }
    ...

失败并显示如下错误信息:

2021/10/07 13:29:50 [emerg] 183#183: pcre_compile() 失败: 在 /usr/local/openresty/nginx/conf/conf.d/local.dev.conf:26 中“(abc|def”缺少 )
nginx: [emerg] pcre_compile() 失败: 在 /usr/local/openresty/nginx/conf/conf.d/local.dev.conf:26 中“(abc|def”缺少 )

有趣的是,这似乎是“有效”的。

        if ($request_uri !~ "(abc|def))" {
            return 404;
        }

原文链接 https://stackoverflow.com/questions/69482163

点赞
stackoverflow用户6756090
stackoverflow用户6756090

你漏了 if ( 的闭合 )

if ($request_uri !~ "(abc|def)") {
    return 404;
}
2021-10-07 13:42:31