6

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
  • 2
    Try location ~* "^/[a-z0-9]{24}$"
    – Drifter104
    Jan 7, 2016 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. Jan 7, 2016 at 23:02

1 Answer 1

3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .