1
location ~ ^/test/(?<id>\d+)$ {
    postgres_pass    database;
    rds_json         on;
    postgres_escape  $name $id;
    postgres_query   "SELECT $name";
}

上面的代码片段取自https://github.com/FRiCKLE/ngx_postgres/issues/4

有人可以向我解释 ^ 的作用和 $ 的作用吗?我找不到解释它的文档。已经检查了https://github.com/FRiCKLE/ngx_postgreshttp://nginx.org/en/docs/http/ngx_http_core_module.html#location

4

1 回答 1

3

那是一个正则表达式。谷歌正则表达式。

^匹配字符串的开头并$匹配结尾。换句话说,这个正则表达式只有在 和 之间的部分与 的所有值匹配^时才$匹配location。因此,只有以 开头/test/、后跟一个或多个数字和字符串结尾的 URL 才会匹配。

于 2015-09-28T04:17:27.633 回答