Init_by_lua_block configuration in KONG_NGINX_HTTP_INCLUDE causes start up errors

Hi, I have some code that I would like to run during the configuration loading phase of Kong. To setup variables and stuff that I need.

In Openresty this configuration sample gets loaded without an issue, In Kong however the init_by_lua_block in my extra configuration causes start up issues of the Kong service.

It seems like both the default Kong configuration has its own init_by_lua_block and my extra configuration has one as well confusing Kong? How can get my extra init_by_lua_block to exist side by side with the default Kong configuration?

Note: I am using Kong version 1.3.0rc1-alpine docker image because I want to use the grpc directives from Openresty.

2019/08/20 07:59:27 [verbose] Kong: 1.3.0rc1
kong_1                | Error: 
kong_1                | /usr/local/share/lua/5.1/kong/cmd/prepare.lua:12: could not prepare Kong prefix at /usr/local/kong: nginx configuration is invalid (exit code 1):
kong_1                | nginx: [alert] lua_code_cache is off; this will hurt performance in /configs/grpc.kong.conf:1
kong_1                | nginx: [emerg] is duplicate in /usr/local/kong/nginx-kong.conf:35
kong_1                | nginx: configuration file /usr/local/kong/nginx.conf test failed
kong_1                | 
kong_1                | stack traceback:
kong_1                | 	[C]: in function 'error'
kong_1                | 	/usr/local/share/lua/5.1/kong/cmd/prepare.lua:12: in function 'cmd_exec'
kong_1                | 	/usr/local/share/lua/5.1/kong/cmd/init.lua:87: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:87>
kong_1                | 	[C]: in function 'xpcall'
kong_1                | 	/usr/local/share/lua/5.1/kong/cmd/init.lua:87: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:44>
kong_1                | 	/usr/local/bin/kong:9: in function 'file_gen'
kong_1                | 	init_worker_by_lua:49: in function <init_worker_by_lua:47>
kong_1                | 	[C]: in function 'xpcall'
kong_1                | 	init_worker_by_lua:56: in function <init_worker_by_lua:54>
kong_1                | 2019/08/20 07:59:27 [verbose] no config file found at /etc/kong/kong.conf
kong_1                | 2019/08/20 07:59:27 [verbose] no config file found at /etc/kong.conf
kong_1                | 2019/08/20 07:59:27 [verbose] no config file, skip loading
kong_1                | 2019/08/20 07:59:27 [verbose] prefix in use: /usr/local/kong
kong_1                | 2019/08/20 07:59:27 [verbose] preparing nginx prefix directory at /usr/local/kong
kong_1                | 2019/08/20 07:59:27 [verbose] SSL enabled, no custom certificate set: using default certificate
kong_1                | 2019/08/20 07:59:27 [verbose] default SSL certificate found at /usr/local/kong/ssl/kong-default.crt

Sample extra configuration file to be loaded when Kong starts

lua_code_cache off;

init_by_lua_block {
  -- Define global import paths
  PROTOC_IMPORT_PATHS = {
    "/usr/local/protoc/include"
  }
}

server {
  listen 8000;
  server_name localhost;

   location /rest {
   access_by_lua_block { SOME_CODE}
   body_filter_by_lua_block {SOME_CODE}
   grpc_set_header Content-Type application/grpc;
    grpc_pass  app:50051;
   }
  
}

Is it not possible to have init_by_lua_blocks in the extra included configurations?

This is not possible.
You will have to create a custom Nginx template and then pass it to Kong.

Please see: https://docs.konghq.com/1.2.x/configuration/