0

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
  • 1
    And have \i at the start of the regexp. It is an unknown escape sequence.
    – AlexD
    Commented Dec 30, 2021 at 15:46

3 Answers 3

1

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.

0

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

-1

Removing \ from index.htm(l?) worked for me.

New configuration will look like this

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

This change should not affect the behavior of your configuration, as it will still match index.htm or index.html in a case-insensitive manner.

As for the difference between Nginx 1.21.4 and 1.21.5, it's possible that the newer version has stricter validation for regular expressions, which is why it's now throwing an error for a previously accepted configuration.

You must log in to answer this question.