4

I have a pretty simple location block in my nginx conf that looks like this:

location ~* ^\/[a-z0-9]{24}$ {
    // do some things
}

I'm attempting to catch urls that end in a Mongo ObjectId. eg: https://example.com/5550cdea6928495a25bb8df8

For some reason nginx is telling me there is an error:

2016/01/07 22:36:32 [emerg] 26445#0: unknown directive "24}$" in /etc/nginx/sites-enabled/mysite.com:32
  • 2
    Try location ~* "^/[a-z0-9]{24}$" – Drifter104 Jan 7 '16 at 23:01
  • 3
    Your regex contains a brace, so you should put it in double quotes: location ~* "^/[a-z0-9]{24}$". And the backslash in front of slash is not required. – Richard Smith Jan 7 '16 at 23:02
1

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

If a regular expression includes the “}” or “;” characters, the whole expressions should be enclosed in single or double quotes.

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.