{"id":13777599,"url":"https://github.com/anjia0532/lua-resty-maxminddb","last_synced_at":"2025-03-16T18:31:34.194Z","repository":{"id":39121640,"uuid":"103599345","full_name":"anjia0532/lua-resty-maxminddb","owner":"anjia0532","description":"A Lua library for reading MaxMind's Geolocation database","archived":false,"fork":false,"pushed_at":"2023-11-18T14:13:44.000Z","size":98,"stargazers_count":93,"open_issues_count":1,"forks_count":30,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-02-15T02:31:04.363Z","etag":null,"topics":["geo","geoip","lua","luajit","maxmind","maxmind-db","maxmind-geoip","openresty"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anjia0532.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-09-15T01:27:06.000Z","updated_at":"2023-10-31T18:22:25.000Z","dependencies_parsed_at":"2024-01-13T10:43:14.007Z","dependency_job_id":"d02cb4bd-1cc2-4612-a6e7-7c2a70b85c17","html_url":"https://github.com/anjia0532/lua-resty-maxminddb","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjia0532%2Flua-resty-maxminddb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjia0532%2Flua-resty-maxminddb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjia0532%2Flua-resty-maxminddb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anjia0532%2Flua-resty-maxminddb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anjia0532","download_url":"https://codeload.github.com/anjia0532/lua-resty-maxminddb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826788,"owners_count":20354220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geo","geoip","lua","luajit","maxmind","maxmind-db","maxmind-geoip","openresty"],"created_at":"2024-08-03T18:00:45.939Z","updated_at":"2025-03-16T18:31:33.771Z","avatar_url":"https://github.com/anjia0532.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"Name\n---\nlua-resty-maxminddb - A Lua library for reading [MaxMind's Geolocation database format](https://maxmind.github.io/MaxMind-DB/)  (aka mmdb or geoip2).\n\n\nPrerequisites\n---\n\n**Note**\n- [maxmind/libmaxminddb][]\n\n- [openresty][]\n\n- [GeoLite2 Free Downloadable Databases][linkGeolite2FreeDownloadableDatabases]\n\n- [maxmind/geoipupdate][]\n\n\n**Bug fixed**\n\n- [Error at lookup IP](https://github.com/anjia0532/lua-resty-maxminddb/issues/5)\n\n- [bad argument #1 to 'concat' (table expected, got nil)](https://github.com/anjia0532/lua-resty-maxminddb/issues/4)\n\n- [Memory leak](https://github.com/anjia0532/lua-resty-maxminddb/issues/6)\n\n- [Multiple subdivisions](https://github.com/anjia0532/lua-resty-maxminddb/issues/7)\n\n**Apology for infringement**\n- https://github.com/anjia0532/lua-resty-maxminddb/issues/25\n\nInstallation\n---\n```bash\n\n# opm (manual install libmaxminddb and download GeoLite2-City.mmdb)\n# openresty/openresty:alpine and apache/apisix:2.13.0-alpine docker image need to install perl libmaxminddb\n# e.g. apk --no-cache add perl libmaxminddb \u0026\u0026 ln -s /usr/lib/libmaxminddb.so.0  /usr/lib/libmaxminddb.so\nopm get anjia0532/lua-resty-maxminddb\n\n# luarocks (manual download GeoLite2-City.mmdb)\n# openresty/openresty:alpine-fat docker image\nluarocks install lua-resty-maxminddb\n\n# openresty/openresty:alpine docker image need to install luarocks (ref https://github.com/openresty/docker-openresty/blob/master/alpine/Dockerfile.fat)\n\n# special apache/apisix:2.xx.0-alpine luarocks install lua-resty-maxminddb UNZIP=/usr/bin/unzip\n# e.g. apk --no-cache add perl alpine-sdk \u0026\u0026 luarocks install lua-resty-maxminddb UNZIP=/usr/bin/unzip\n```\n\nSynopsis\n---\n\n```\nserver {\n    listen 80;\n    server_name localhost;\n    location / {\n        content_by_lua_block{\n            local cjson = require 'cjson'\n            local geo = require 'resty.maxminddb'\n            if not geo.initted() then\n                geo.init(\"/path/to/GeoLite2-City.mmdb\")\n            end\n            local res,err = geo.lookup(ngx.var.arg_ip or ngx.var.remote_addr) --support ipv6 e.g. 2001:4860:0:1001::3004:ef68\n\n            if not res then\n                ngx.log(ngx.ERR,'failed to lookup by ip ,reason:',err)\n            end\n            ngx.say(\"full :\",cjson.encode(res))\n            if ngx.var.arg_node then\n               ngx.say(\"node name:\",ngx.var.arg_node,\" ,value:\", cjson.encode(res[ngx.var.arg_node] or {}))\n            end\n        }\n    }\n}\n```\n\n```bash\n  #ipv4\n  $ curl localhost/?ip=114.114.114.114\u0026node=city\n  \n  #ipv6\n  #$ curl localhost/?ip=2001:4860:0:1001::3004:ef68\u0026node=country\n  \n  full :{\"city\":{\"geoname_id\":1799962,\"names\":{\"en\":\"Nanjing\",\"ru\":\"Нанкин\",\"fr\":\"Nankin\",\"pt-BR\":\"Nanquim\",\"zh-CN\":\"南京\",\"es\":\"Nankín\",\"de\":\"Nanjing\",\"ja\":\"南京市\"}},\"subdivisions\":[{\"geoname_id\":1806260,\"names\":{\"en\":\"Jiangsu\",\"fr\":\"Province de Jiangsu\",\"zh-CN\":\"江苏省\"},\"iso_code\":\"32\"}],\"country\":{\"geoname_id\":1814991,\"names\":{\"en\":\"China\",\"ru\":\"Китай\",\"fr\":\"Chine\",\"pt-BR\":\"China\",\"zh-CN\":\"中国\",\"es\":\"China\",\"de\":\"China\",\"ja\":\"中国\"},\"iso_code\":\"CN\"},\"registered_country\":{\"geoname_id\":1814991,\"names\":{\"en\":\"China\",\"ru\":\"Китай\",\"fr\":\"Chine\",\"pt-BR\":\"China\",\"zh-CN\":\"中国\",\"es\":\"China\",\"de\":\"China\",\"ja\":\"中国\"},\"iso_code\":\"CN\"},\"location\":{\"time_zone\":\"Asia\\/Shanghai\",\"longitude\":118.7778,\"accuracy_radius\":50,\"latitude\":32.0617},\"continent\":{\"geoname_id\":6255147,\"names\":{\"en\":\"Asia\",\"ru\":\"Азия\",\"fr\":\"Asie\",\"pt-BR\":\"Ásia\",\"zh-CN\":\"亚洲\",\"es\":\"Asia\",\"de\":\"Asien\",\"ja\":\"アジア\"},\"code\":\"AS\"}}\n  node name:city ,value:{\"geoname_id\":1799962,\"names\":{\"en\":\"Nanjing\",\"ru\":\"Нанкин\",\"fr\":\"Nankin\",\"pt-BR\":\"Nanquim\",\"zh-CN\":\"南京\",\"es\":\"Nankín\",\"de\":\"Nanjing\",\"ja\":\"南京市\"}}\n```\n\nprettify\n```json\nfull: {\n    \"city\": {\n        \"geoname_id\": 1799962,\n        \"names\": {\n            \"en\": \"Nanjing\",\n            \"ru\": \"Нанкин\",\n            \"fr\": \"Nankin\",\n            \"pt-BR\": \"Nanquim\",\n            \"zh-CN\": \"南京\",\n            \"es\": \"Nankín\",\n            \"de\": \"Nanjing\",\n            \"ja\": \"南京市\"\n        }\n    },\n    \"subdivisions\": [{\n            \"geoname_id\": 1806260,\n            \"names\": {\n                \"en\": \"Jiangsu\",\n                \"fr\": \"Province de Jiangsu\",\n                \"zh-CN\": \"江苏省\"\n            },\n            \"iso_code\": \"32\"\n        }\n    ],\n    \"country\": {\n        \"geoname_id\": 1814991,\n        \"names\": {\n            \"en\": \"China\",\n            \"ru\": \"Китай\",\n            \"fr\": \"Chine\",\n            \"pt-BR\": \"China\",\n            \"zh-CN\": \"中国\",\n            \"es\": \"China\",\n            \"de\": \"China\",\n            \"ja\": \"中国\"\n        },\n        \"iso_code\": \"CN\"\n    },\n    \"registered_country\": {\n        \"geoname_id\": 1814991,\n        \"names\": {\n            \"en\": \"China\",\n            \"ru\": \"Китай\",\n            \"fr\": \"Chine\",\n            \"pt-BR\": \"China\",\n            \"zh-CN\": \"中国\",\n            \"es\": \"China\",\n            \"de\": \"China\",\n            \"ja\": \"中国\"\n        },\n        \"iso_code\": \"CN\"\n    },\n    \"location\": {\n        \"time_zone\": \"Asia\\/Shanghai\",\n        \"longitude\": 118.7778,\n        \"accuracy_radius\": 50,\n        \"latitude\": 32.0617\n    },\n    \"continent\": {\n        \"geoname_id\": 6255147,\n        \"names\": {\n            \"en\": \"Asia\",\n            \"ru\": \"Азия\",\n            \"fr\": \"Asie\",\n            \"pt-BR\": \"Ásia\",\n            \"zh-CN\": \"亚洲\",\n            \"es\": \"Asia\",\n            \"de\": \"Asien\",\n            \"ja\": \"アジア\"\n        },\n        \"code\": \"AS\"\n    }\n}\nnode name: city, value: {\n    \"geoname_id\": 1799962,\n    \"names\": {\n        \"en\": \"Nanjing\",\n        \"ru\": \"Нанкин\",\n        \"fr\": \"Nankin\",\n        \"pt-BR\": \"Nanquim\",\n        \"zh-CN\": \"南京\",\n        \"es\": \"Nankín\",\n        \"de\": \"Nanjing\",\n        \"ja\": \"南京市\"\n    }\n}\n\n```\n\nReferences\n---\n\n- [GeoIP2 City and Country CSV Databases][linkGeoip2CityAndCountryCsvDatabases]\n- [lilien1010/lua-resty-maxminddb][]\n- [maxmind/libmaxminddb#source#lookup_and_print][]\n- [maxmind/libmaxminddb#source#dump_entry_data_list][]\n\nBug Reports\n---\nPlease report bugs by filing an issue with our GitHub issue tracker at https://github.com/anjia0532/lua-resty-maxminddb/issues\n\nIf the bug is casued by libmaxminddb  tracker at https://github.com/maxmind/libmaxminddb/issues\n\nCopyright and License\n=====================\n\nThis module is licensed under the apache LICENSE-2.0 license.\n\nCopyright 2017-now anjia (anjia0532@gmail.com)\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\n\nyou may not use this file except in compliance with the License.\n\nYou may obtain a copy of the License at\n\n\thttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\n\ndistributed under the License is distributed on an \"AS IS\" BASIS,\n\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\nSee the License for the specific language governing permissions and\n\nlimitations under the License.\n\n[maxmind/libmaxminddb]: https://github.com/maxmind/libmaxminddb\n[openresty]: https://openresty.org/en/installation.html\n[linkGeolite2FreeDownloadableDatabases]: http://dev.maxmind.com/geoip/geoip2/geolite2/\n[maxmind/geoipupdate]: https://github.com/maxmind/geoipupdate\n[linkGeoip2CityAndCountryCsvDatabases]: https://dev.maxmind.com/geoip/geoip2/geoip2-city-country-csv-databases/\n[maxmind/libmaxminddb#source#lookup_and_print]: https://github.com/maxmind/libmaxminddb/blob/master/bin/mmdblookup.c#L262\n[maxmind/libmaxminddb#source#dump_entry_data_list]: https://github.com/maxmind/libmaxminddb/blob/master/src/maxminddb.c#L1938\n[lilien1010/lua-resty-maxminddb]: https://github.com/lilien1010/lua-resty-maxminddb\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanjia0532%2Flua-resty-maxminddb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanjia0532%2Flua-resty-maxminddb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanjia0532%2Flua-resty-maxminddb/lists"}