S
S
Semen Frolov2020-03-08 23:15:11
Nginx
Semen Frolov, 2020-03-08 23:15:11

How to understand lua_code_cache & content_by_lua_file, why doesn't it work if cache is enabled?

Hello, help me understand how lua_code_cache works.

nginx location:

location ~ ^/page/(\d+)/(\d+) {   # items, page number
       default_type 'text/html';
       content_by_lua_file $template_root/index.lua;
       lua_code_cache off;
    }


index.lua :
local http = require "resty.http"
local httpc = http.new()
local cjson = require "cjson"
local template = require "resty.template" 

...

----


Everything works exactly until the moment when we turn on the cache lua_code_cache on; (or comment, which is the same)

Error:
2020/03/08 19:51:56 [error] 6#6: *31 lua entry thread aborted: runtime error: [string "context=... or {}..."]:101: bad argument #1 to 'ipairs' (table expected, got number)
openresty_1          | stack traceback:
openresty_1          | coroutine 0:
openresty_1          | 	[C]: in function 'ipairs'
openresty_1          | 	[string "context=... or {}..."]:101: in main chunk
openresty_1          | 	/usr/local/openresty/site/lualib/resty/template.lua:475: in function 'render'
openresty_1          | 	/var/www/lua/index.lua:70: in main chunk, client: 87.117.185.65, server: _, request: "GET / HTTP/1.1", host: "site.com"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question