upyun / lua-resty-checkups

Manage Nginx upstreams in pure Lua.
259 stars 65 forks source link

demo报错 #51

Closed lee3164 closed 4 years ago

lee3164 commented 4 years ago

我按照 demo进行操作,报这样的错误 2019/12/18 15:28:09 [error] 55676#12685090: init_by_lua error: init_by_lua:4: attempt to call field 'init' (a nil value) stack traceback: init_by_lua:4: in main chunk

下面是 配置文件片段

lua_package_path "/usr/local/etc/openresty/config.lua;;";
    lua_code_cache on;

    lua_shared_dict state 10m;
    lua_shared_dict mutex 1m;
    lua_shared_dict locks 1m;
    lua_shared_dict config 10m;

    init_by_lua_block {
        local config = require "config.lua"
        local checkups = require "resty.checkups.api"
        checkups.init(config)
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

    location /hehe {
        default_type 'text/plain';
        content_by_lua_block {
            ngx.say(package.path)
            ngx.say(package.cpath)
        }
    }

下面是我的 package.path image

下面是我的package的位置 image

我是通过 opm get upyun/lua-resty-checkups 来安装的 可以看出 这个库是位于 package.path里面的,但是 为啥会报错啊?

huangnauh commented 4 years ago

lua_package_path 设置问题

https://pgl.yoyo.org/luai/i/package.loaders

For each template, the searcher will change each interrogation mark in the template by filename, which is the module name with each dot replaced by a "directory separator" (such as "/" in Unix); then it will try to open the resulting file name. So, for instance, if the Lua path is the string

"./?.lua;./?.lc;/usr/local/?/init.lua"

the search for a Lua file for module foo will try to open the files ./foo.lua, ./foo.lc, and /usr/local/foo/init.lua, in that order.