0

In my nginx config file I have this location block (modified for debugging purposes):

location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
    expires 1;
    log_not_found off;
    return 515 "Request URI is $request_uri. Caught you";
}

When I request this URI from the server: /img/signup/be0e1d34fabf2514d49db9baec09f858.png?w=198&h=198&s=9a7d22504c5ae176a936a0f18cccacba

sure enough, it matches and I get a 515 response with this body: Request URI is /img/signup/be0e1d34fabf2514d49db9baec09f858.png?w=198&h=198&s=9a7d22504c5ae176a936a0f18cccacba. Caught you

Why? The regex doesn't match, at least not intuitively (either it must end in a question mark followed by a series of digits, or in .png etc.), nor when I sense-checked it at Regex101.com.

mpavey
  • 433
  • 4
  • 6

1 Answers1

0

Nginx isn't actually matching against the section after the question mark. Those are the query args. Nginx is only seeing up until the end of the path (.png). Since that's the case, it matches just fine.