^ 和 $ 在 nginx.conf 位置做什么?
What does ^ and $ do in nginx.conf location?
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_postgres and http://nginx.org/en/docs/http/ngx_http_core_module.html#location。
这是一个正则表达式。 Google 正则表达式。
^
匹配字符串的开头,$
匹配结尾。换句话说,只有当 ^
和 $
之间的部分匹配 location
的所有值时,此正则表达式才匹配。因此,只有以 /test/
开头,后跟一个或多个数字和字符串结尾的 URL 才会匹配。
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_postgres and http://nginx.org/en/docs/http/ngx_http_core_module.html#location。
这是一个正则表达式。 Google 正则表达式。
^
匹配字符串的开头,$
匹配结尾。换句话说,只有当 ^
和 $
之间的部分匹配 location
的所有值时,此正则表达式才匹配。因此,只有以 /test/
开头,后跟一个或多个数字和字符串结尾的 URL 才会匹配。