Search code examples
nginxkong

Kong 2.0.2 Serving api and static content


Problem: I am trying to customize the nginx config that gets generated by kong to serve static content as well as my api as described here. I can get the nginx.conf file to be generated, but for the life of me -I can't get my simple HTML to be served.

What I've Done: I've created a minimal docker-compose that reproduces my issue here. I've tried all sorts of combinations here and I universally get the same result:

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

The only logs I can see that are relevant are:

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"

I've tried moving root out of location, using alias instead of root, passing a host header, changing the server_name, and a thousand other things I can't remember.

I believe the problem lies here but I have no idea at this point. I think this is the problem because I can get it to return text if I change the body to:

location / { 
  return 200 'huh?';
}

Any help would add a few years back to my life.

EDIT I stripped out everything except the bare essentials for location / and location /api/ and this works -so I can try building up from here to find the cause.

EDIT It appears as though this commit contains the breaking change, it's unclear to me what the breaking change is though.


Solution

  • I was able to isolate the problem, and in hindsight it was quite obvious. These kong directives need to go only inside the location block for api, and not for the static content.

                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()
                }
    

    See the commit that fixed the issue here