如何编写 Nginx 位置以捕获查询字符串中问号后的所有内容?

How do I write an Nginx location to capture everything after a question mark in a query string?

我有一个 URL 看起来像这样:

http://somedomain.loc/api/things/index?take=10&skip=0&page=1&pageSize=10&sort%5B0%5D%5Bfield%5D=date_created&sort%5B0%5D%5Bdir%5D=desc

我需要一个匹配 /api/things/index 的 Nginx 位置,并捕获 ? 之后查询字符串中的所有内容。我试过这个:

location ~ /api/things/index?(.*) {
    return 200 ;
}

但是</code>是空的。如果我更改它以捕获整个内容,例如:</p> <pre><code>location ~ (/api/things/index?.*)

我得到 /api/things/index,但问号后什么也没有。我已经在几个在线正则表达式测试器中尝试过正则表达式,并且捕获似乎有效,但一定有一些我不理解的关于 Nginx 位置的东西。请帮忙!

你也许可以试试这个

location ~/api/things/index/(.*)$ {
  return 200 ;
}

从 OP 编辑​​
如下面的评论所示,事实证明我的问题与其说是正则表达式,不如说是使用捕获而不是 $args。解决方案是:

location ~/api/things/index(.*)$ {
    return 200 $args;
}