【问题标题】:how to get url parameter and pass to proxy_pass using nginx如何使用 nginx 获取 url 参数并传递给 proxy_pass
【发布时间】:2018-11-24 18:08:19
【问题描述】:

我需要从 URL 中获取参数,例如 abc=MY_STRING:

https://my-address/test?abc=MY_STRING

并且在反向代理(我的地址)上,是这样配置的:

location /test?(.*) {
  proxy_pass http://local-server:1234/test?$args
}

但它不起作用。

我尝试了另一种配置:

location /test?(.*) {
  proxy_pass http://local-server:1234/test?$1
}

但也没有用。

【问题讨论】:

    标签: nginx nginx-reverse-proxy nginx-config


    【解决方案1】:

    您不能将 URI 的查询字符串部分与 locationrewrite 语句匹配,因为它不是 normalized URI 的一部分。

    但你不需要。 URI(完整的查询字符串)将在上游传递 除非您使用 rewritetry_files 语句重定向它。

    例如:

    location /test {
        proxy_pass http://localhost:1234;
    }
    

    URI /test?abc=MY_STRING 将匹配该位置并传递给localhost:1234 完全相同。请参阅this document 了解更多信息。

    【讨论】:

    • 它在我从位置块中删除 try_files 后工作。谢谢。
    猜你喜欢
    • 2020-10-20
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    相关资源
    最近更新 更多