Home > database >  Nginx regex pcre_compile() failed
Nginx regex pcre_compile() failed

Time:10-08

Can someone explain why the following condition is failing? Seems like the last ) is cut off.

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

fails with:

2021/10/07 13:29:50 [emerg] 183#183: pcre_compile() failed: missing ) in "(abc|def" in /usr/local/openresty/nginx/conf/conf.d/local.dev.conf:26
nginx: [emerg] pcre_compile() failed: missing ) in "(abc|def" in /usr/local/openresty/nginx/conf/conf.d/local.dev.conf:26

Funny enough, this seems to be "valid".

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

CodePudding user response:

You are missing the closing ) of the if (.

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