【问题标题】:Add an API in Kong在 Kong 中添加 API
【发布时间】:2016-11-25 14:51:25
【问题描述】:

REST 和 API 网关的新功能。

我已经在开发机器上安装了带有 Cassandra 的 Kong,我正在尝试添加我的 API(spring-boot 应用程序),但阅读文档我很难让它工作。

我的 API:

http://ff-nginxdev-01:9003/fund-information-services/first-information/fund/{fundId}

当我跑步时

http http://ff-nginxdev-01:9003/fund-information-services/first-information/fund/630

    HTTP/1.1 200
    Content-Type: application/json;charset=UTF-8
    Date: Fri, 25 Nov 2016 14:47:30 GMT
    Transfer-Encoding: chunked
    X-Application-Context: application:9003

    {
        "assetSplit": {
            "allocationHistories": [
                {
                    "key": {
                        "asset": {
                            "description": "Other Far East",
                            "id": 18
                        },
                        "assetSplit": "09",
                        "effectiveDate": 1430348400000
                    },
    ......
    ......

一切看起来都很好,我可以检索 Json 消息。

在 Kong 中添加 API:

http POST http://ff-nginxdev-01:8001/apis/ name=fund-information upstream_url=http://ff-nginxdev-01:9003/ request_path=/fund-information-services


    HTTP/1.1 201 Created
    Access-Control-Allow-Origin: *
    Connection: keep-alive
    Content-Type: application/json; charset=utf-8
    Date: Fri, 25 Nov 2016 14:39:45 GMT
    Server: kong/0.9.4
    Transfer-Encoding: chunked

    {
        "created_at": 1480084785000,
        "id": "fdcc76d7-e2a2-4816-8f27-d506fdd32c0a",
        "name": "fund-information",
        "preserve_host": false,
        "request_path": "/fund-information-services",
        "strip_request_path": false,
        "upstream_url": "http://ff-nginxdev-01:9003/"
    }

测试 Kong API 网关:

http http://ff-nginxdev-01:8000/fund-information-services/first-information/fund/630

HTTP/1.1 502 Bad Gateway
Connection: keep-alive
Content-Type: text/plain; charset=UTF-8
Date: Fri, 25 Nov 2016 14:44:33 GMT
Server: kong/0.9.4
Transfer-Encoding: chunked

An invalid response was received from the upstream server

我知道我遗漏了一些东西,但我不清楚。

【问题讨论】:

  • Nginx 可能无法解析ff-nginxdev-01。确保正确配置 Nginx 以使用能够解析它的解析器(您可以通过 Kong 的配置文件这样做)并最好使用 FQDN。

标签: api spring-boot kong


【解决方案1】:

默认情况下,动态 SSL 插件会将特定的 SSL 证书绑定到 API 中的 request_host。 您只需在 API 中定义 request_path,这意味着当您使用 request_path 时 SSL 插件不适用。

您可以阅读更多内容以了解为什么会这样:this issue

为了使您的请求有效,我认为您应该阅读有关如何代理 API 的内容:Proxy Reference

这是我的解决方案:

方法一:将“strip_request_path”改为true

"strip_request_path": true

此方法假设您没有先指定 request_host

方法二:使用 request_host 代替

"request_host" : "your_api"

然后在您的请求标头中,您应该添加这个 request_host:

示例请求:

curl -i -X POST --url http://ff-nginxdev-01:8000/fund-information-services/first-information/fund/630 --header 'Host: your_api' 

它会起作用的

【讨论】:

    【解决方案2】:

    你错过了 kong "fund-information" 知道的 api 名称,所以如果你这样做

    http POST http://ff-nginxdev-01:8001/apis/name=fund-information upstream_url=http://ff-nginxdev-01:9003request_path=/fund-information-services

    您的测试网址是 httphttp://ff-nginxdev-01:8000/fund-information/first-information/fund/630

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      • 2018-04-29
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多