为什么 nginx 声称在我的 `rewrite` 语句中没有终止分号?
Why is nginx claiming there's no terminating semicolon in my `rewrite` statement?
当且仅当 cookie 存在时,我想将 URL 重定向到 Django 平台(通过 uwsgi)。如果做不到这一点,我需要将执行推迟到 content_by_lua
插件。
下面是我对这种逻辑的尝试:
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/ break;
uwsgi_pass frontend;
}
content_by_lua '
ngx.say("Ping! You got here because you have no cookies!")
';
}
Nginx 认为有必要且适当地使用以下日志消息来侮辱我的智商:
nginx: [emerg] directive "rewrite" is not terminated by ";" in /opt/openresty/nginx/conf/nginx.conf:34
也许我和 nginx 似乎想的一样密集,但是我错过了什么?
奖金问题:我的一般方法安全和理智吗?有没有更好的方法来实现我的目标?
这对我来说其实是一件非常愚蠢的事情,我错了。 Nginx 使用 curly-braces {}
来分隔块,因此当这些用于正则表达式时,表达式必须包含在 double-quotes.
中
额外答案:您也可以在位置匹配期间捕获 UUID 值,以避免在重写时使用额外的正则表达式,如下所示:
location ~* "^/([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})$" { # match and capture a UUID v4
include uwsgi_params;
set $uuid ;
if ($cookie_admin) {
# if cookie exists, rewrite /<uuid> to /modif/<uuid> and pass to uwsgi
rewrite / /modif/$uuid break;
uwsgi_pass frontend;
}
content_by_lua '
ngx.say("Ping! You got here because you have no cookies!")
ngx.say("UIID: " .. ngx.var.uuid)
';
}
当且仅当 cookie 存在时,我想将 URL 重定向到 Django 平台(通过 uwsgi)。如果做不到这一点,我需要将执行推迟到 content_by_lua
插件。
下面是我对这种逻辑的尝试:
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/ break;
uwsgi_pass frontend;
}
content_by_lua '
ngx.say("Ping! You got here because you have no cookies!")
';
}
Nginx 认为有必要且适当地使用以下日志消息来侮辱我的智商:
nginx: [emerg] directive "rewrite" is not terminated by ";" in /opt/openresty/nginx/conf/nginx.conf:34
也许我和 nginx 似乎想的一样密集,但是我错过了什么?
奖金问题:我的一般方法安全和理智吗?有没有更好的方法来实现我的目标?
这对我来说其实是一件非常愚蠢的事情,我错了。 Nginx 使用 curly-braces {}
来分隔块,因此当这些用于正则表达式时,表达式必须包含在 double-quotes.
额外答案:您也可以在位置匹配期间捕获 UUID 值,以避免在重写时使用额外的正则表达式,如下所示:
location ~* "^/([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})$" { # match and capture a UUID v4
include uwsgi_params;
set $uuid ;
if ($cookie_admin) {
# if cookie exists, rewrite /<uuid> to /modif/<uuid> and pass to uwsgi
rewrite / /modif/$uuid break;
uwsgi_pass frontend;
}
content_by_lua '
ngx.say("Ping! You got here because you have no cookies!")
ngx.say("UIID: " .. ngx.var.uuid)
';
}