unrecognized character follows \ in "\index.htm(l?)" after updating to nginx 1.21.5

My docker image has suddenly failed after build with error message:

2021/12/30 16:02:26 [emerg] 16#16: pcre2_compile() failed: unrecognized character follows \ in "\index.htm(l?)" at "index.htm(l?)" in /etc/nginx/conf.d/default.conf:37

We are building docker image from nginx:latest, which is currently 1.21.5.

I've degraded to nginx 1.21.4 and it starts without an issue.

My problematic configuration is:

    location ~* \index.htm(l?) {
        add_header Cache-Control 'no-cache, no-store, must-revalidate';
    }

Was there any breaking change indroduced between nginx 1.12.4 and 1.12.5, or I was using a deprecated syntax? I've never got any warning about it.


Thanks to AlexD comment I've found out the actual problem:

The change in the nginx 1.21.5 is switching from PCRE to PCRE2. PCRE2 is compatible with previous version, except it's not tolerant against many errors that were ignored by previous version.

The problem in my case was 'escaping' of the first letter, which was not correct escaping (copy-paste from another case, where the dot was escaped).

PCRE has silently ignored 'escaping' and processed regex as if '' were not present.

PCRE2 throws error.


In the release notes they state that it is now "built with the PCRE2 library by default". Perhaps this is stricter when parsing unknown escape sequences than before.

https://nginx.org/en/CHANGES