anjia0532 / lua-resty-maxminddb

A Lua library for reading MaxMind's Geolocation database
Apache License 2.0
97 stars 30 forks source link

loop or previous error loading module 无法使用 #18

Closed qw2283345 closed 3 years ago

qw2283345 commented 5 years ago

使用命令安装 opm get anjia0532/lua-resty-maxminddb 安装成功 配置如下: image

一测试就报错了

[error] 119384#0: *17 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:72):3: loop or previous error loading module 'resty.maxminddb' openresty 1.13.6.2 这个问题,一直都没找到原因,是因为版本问题吗?

anjia0532 commented 5 years ago

/path/to/xxx.mmdb == 你的xx。mmdb所在的绝对路径

qw2283345 commented 5 years ago

不是这个问题,我配置那里的路径就是正确的绝对路径 我的lua文件就只有这一句代码,就报错都是报错的 local geo = require ('resty.maxminddb') 这个问题一般都是指重复引入包问题,但是我只有这一句代码,所以实在想不通

anjia0532 commented 5 years ago

贴一下你的环境 你的nginx的最小化完整配置

qw2283345 commented 5 years ago

系统 CentOS Linux release 7.4.1708 (Core)

openresty -V

nginx version: openresty/1.13.6.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.13 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.5 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-stream --with-stream_ssl_module --with-http_ssl_module

nginx 配置

location /geo {
            default_type "text/html";
            charset utf-8;
            content_by_lua_file  conf/geo_country.lua;
}

geo_country.lua内容

local cjson = require 'cjson'
local geo = require 'resty.maxminddb'

if not geo.initted() then
    geo.init("/usr/local/openresty/geo/GeoLite2-Country.mmdb")
end
local res,err = geo.lookup(ngx.var.arg_ip or ngx.var.remote_addr) --support ipv6 e.g. 2001:4860:0:1001::3004:ef68

if not res then
    ngx.log(ngx.ERR,'failed to lookup by ip ,reason:',err)
end

ngx.say("full :",cjson.encode(res))
if ngx.var.arg_node then
   ngx.say("node name:",ngx.var.arg_node," ,value:", cjson.encode(res[ngx.var.arg_node] or {}))
end
anjia0532 commented 5 years ago

opm get anjia0532/lua-resty-maxminddb后没手动挪过位置吧?

qw2283345 commented 5 years ago

没有的,安装了就没动过,我尝试过。用一台新的机子,重新安装,走最简单的流程配置都不行,所以才想来问问,是不是版本问题

anjia0532 commented 5 years ago

我重新安装的openresty和下载的lib,没问题[捂脸]

qw2283345 commented 5 years ago

我也是重新安装的,还是不行,不过非常感谢你的回答,这个问题,我自己再找找原因,找到了再报告,麻烦你了