【问题标题】:How do I use ngx.location.capture() with proxy_pass in a kong plugin?如何在 kong 插件中使用 ngx.location.capture() 和 proxy_pass?
【发布时间】:2018-01-09 23:02:48
【问题描述】:

我目前正在编写一个 Kong 插件。当我收到带有令牌的请求时,我想请求外部服务来验证令牌。我读到您可以使用 location_capture 和 proxy_pass 来执行外部 HTTP 请求。

我不确定该怎么做。我放了

location = /reqbin { proxy_pass https://requestb.in/yn3pykyn; }

在 nginx_kong.lua 文件中。那是它应该去的地方吗?

在我的插件代码中,我有:

res = ngx.location.capture("/reqbin", {method=ngx.HTTP_POST, args=args})

但是当我使用 curl 请求 Kong 时,请求直接到了 upstream_url,我可以看出我的 requestbin 没有被命中。我做错了什么?

编辑:另外,当前的资源有:

状态:500

正文:无

标题:内容类型:text/plain,服务器:kong/0.10.3

截断:真

【问题讨论】:

    标签: nginx lua openid-connect kong


    【解决方案1】:

    有一个很好的库可以帮助您执行此请求:https://github.com/pintsized/lua-resty-http 我一直在将它用于相同的目的,并且效果很好。

    【讨论】:

      猜你喜欢
      • 2021-09-25
      • 1970-01-01
      • 2018-10-27
      • 2020-09-24
      • 2023-01-22
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多