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.

  • 1
    And have \i at the start of the regexp. It is an unknown escape sequence.
    – AlexD
    Dec 30, 2021 at 15:46

2 Answers 2


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.