【问题标题】:Kong 2.0.2 Serving api and static contentKong 2.0.2 服务 api 和静态内容
【发布时间】:2020-04-04 06:25:04
【问题描述】:

问题:我正在尝试自定义由 kong 生成的 nginx 配置以提供静态内容以及我的 api as described here。我可以生成 nginx.conf 文件,但对于我的一生 - 我无法让我的简单 HTML 被提供。

我做了什么:我创建了一个最小的docker-compose,它重现了我的问题here。我在这里尝试了各种组合,我普遍得到相同的结果:

{"message":"no Route matched with those values"}

我能看到的唯一相关日志是:

2020/04/04 06:20:11 [warn] 49#0: *11361 using uninitialized "kong_proxy_mode" variable, client: 127.0.0.1, server: kong, request: "GET /index.html HTTP/1.1", host: "localhost:8000"
2020/04/04 06:20:11 [warn] 49#0: *11361 using uninitialized "ctx_ref" variable, client: 127.0.0.1, server: kong, request: "GET /index.html HTTP/1.1", host: "localhost:8000"
2020/04/04 06:20:11 [warn] 49#0: *11361 [lua] reports.lua:75: log(): [reports] unknown request scheme: http while logging request, client: 127.0.0.1, server: kong, request: "GET /index.html HTTP/1.1", host: "localhost:8000"

我尝试将root 移出location,使用alias 而不是root,传递主机标头,更改server_name,以及其他一千件事我不记得了。

相信问题在于here,但我目前不知道。我认为这是问题所在,因为如果我将正文更改为,我可以让它返回文本:

location / { 
  return 200 'huh?';
}

任何帮助都会让我的生活恢复几年。

编辑stripped out everything 除了location /location /api/ 的基本要素之外,这是可行的——所以我可以尝试从这里开始寻找原因。

编辑 this commit 似乎包含重大更改,但我不清楚重大更改是什么。

【问题讨论】:

    标签: nginx kong


    【解决方案1】:

    我能够隔离问题,事后看来,这很明显。这些 kong 指令只需要在 api 的 location 块内,而不是静态内容。

                rewrite_by_lua_block {
                    Kong.rewrite()
                }
                access_by_lua_block {
                    Kong.access()
                }
                header_filter_by_lua_block {
                    Kong.header_filter()
                }
                body_filter_by_lua_block {
                    Kong.body_filter()
                }
                log_by_lua_block {
                    Kong.log()
                }
    

    查看修复问题的提交here

    【讨论】:

      猜你喜欢
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-20
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      相关资源
      最近更新 更多