Kong 2.0.2 服务 api 和静态内容

Kong 2.0.2 Serving api and static content

问题:我正在尝试自定义由 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,传递主机 header,更改 server_name,还有一千个我不记得的东西。

相信问题出在here,但我现在还不知道。我认为这是问题所在,因为如果我将 body 更改为:

,我可以将其添加到 return 文本
location / { 
  return 200 'huh?';
}

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

编辑stripped out everything 除了 location /location /api/ 的基本要点,这很有效 - 所以我可以尝试从这里开始寻找原因。

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

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

            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