I'd like to redirect a URL to a Django platform (via uwsgi) if and only if a cookie exists. Failing that, I need to defer execution to the content_by_lua
plugin.
Below is my attempt at such logic:
location ~* "^/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$" { # match a UUID v4
include uwsgi_params;
if ($cookie_admin) {
# if cookie exists, rewrite /<uuid> to /modif/<uuid> and pass to uwsgi
rewrite ^/([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})$ /modif/$1 break;
uwsgi_pass frontend;
}
content_by_lua '
ngx.say("Ping! You got here because you have no cookies!")
';
}
Nginx has deemed it necessary and proper to insult my intelligence with the following log message:
nginx: [emerg] directive "rewrite" is not terminated by ";" in /opt/openresty/nginx/conf/nginx.conf:34
Perhaps I am as dense as nginx seems to think, but what have I missed?
Bonus question: Is my general approach safe and sane? Is there a better way of achieving my goals?