Nginx – Regex location block not working in NGINX

nginxregex

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

Best Answer

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.