Closed jackverse closed 1 year ago
报错: 7#7: *112 [lua] geoip.lua:30: lookup(): failed to lookup by ip,reason:not initialized, client: 172.24.0.1, server: localhost,
我以为是geoIp的ip解析的库没加,我加了一个配置如下 RUN curl -LO https://github.com/maxmind/libmaxminddb/releases/download/1.7.1/libmaxminddb-1.7.1.tar.gz \ && tar -zxvf libmaxminddb-1.7.1.tar.gz \ && chmod 777 libmaxminddb-1.7.1\ && cd libmaxminddb-1.7.1 \ && ./configure \ && make && make install \ && echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf \ && ldconfig
然后再nginx.conf添加了如下
local geoip = require("resty.maxminddb") local mmdb_file = "/usr/local/share/GeoIP/GeoLite2-City.mmdb" geoip:init("/usr/local/share/GeoIP/GeoLite2-City.mmdb", { shm_name = "geoipdb", shm_size = 100 1024 1024, mmdb_file = mmdb_file })
结果发现这个配置好像用处不大,我就不要了,最后我在config里发现一个路径 -- geoip数据文件路径 geoip_db_file = "/usr/local/share/GeoIP/GeoLite2-City.mmdb",
但是我没找到他
最后附上我得dockerfile:
FROM openresty/openresty
RUN sed -i 's/http:\/\/deb.debian.org/http:\/\/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y luarocks
RUN apt-get install -y curl
RUN apt-get install -y libpcre3-dev
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y build-essential
RUN luarocks install lua-resty-core
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
WORKDIR /usr/local/src RUN curl -LO https://github.com/maxmind/libmaxminddb/releases/download/1.7.1/libmaxminddb-1.7.1.tar.gz \ && tar -zxvf libmaxminddb-1.7.1.tar.gz \ && chmod 777 libmaxminddb-1.7.1\ && cd libmaxminddb-1.7.1 \ && ./configure \ && make && make install \ && echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf \ && ldconfig
EXPOSE 80
CMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"]
geoip_db_file = "/usr/local/share/GeoIP/GeoLite2-City.mmdb", 这个数据库文件是要自己下载然后配置路径的。
报错: 7#7: *112 [lua] geoip.lua:30: lookup(): failed to lookup by ip,reason:not initialized, client: 172.24.0.1, server: localhost,
我以为是geoIp的ip解析的库没加,我加了一个配置如下 RUN curl -LO https://github.com/maxmind/libmaxminddb/releases/download/1.7.1/libmaxminddb-1.7.1.tar.gz \ && tar -zxvf libmaxminddb-1.7.1.tar.gz \ && chmod 777 libmaxminddb-1.7.1\ && cd libmaxminddb-1.7.1 \ && ./configure \ && make && make install \ && echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf \ && ldconfig
然后再nginx.conf添加了如下
local geoip = require("resty.maxminddb") local mmdb_file = "/usr/local/share/GeoIP/GeoLite2-City.mmdb" geoip:init("/usr/local/share/GeoIP/GeoLite2-City.mmdb", { shm_name = "geoipdb", shm_size = 100 1024 1024, mmdb_file = mmdb_file })
结果发现这个配置好像用处不大,我就不要了,最后我在config里发现一个路径 -- geoip数据文件路径 geoip_db_file = "/usr/local/share/GeoIP/GeoLite2-City.mmdb",
但是我没找到他
最后附上我得dockerfile:
FROM openresty/openresty
修改 Debian 源
RUN sed -i 's/http:\/\/deb.debian.org/http:\/\/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
更新软件包列表
RUN apt-get update
安装 luarocks
RUN apt-get install -y luarocks
安装 curl
RUN apt-get install -y curl
安装libpcre3-dev
RUN apt-get install -y libpcre3-dev
安装zlib1g-dev
RUN apt-get install -y zlib1g-dev
安装build-essential
RUN apt-get install -y build-essential
安装 lua-resty-core
RUN luarocks install lua-resty-core
设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
下载和安装libmaxminddb
WORKDIR /usr/local/src RUN curl -LO https://github.com/maxmind/libmaxminddb/releases/download/1.7.1/libmaxminddb-1.7.1.tar.gz \ && tar -zxvf libmaxminddb-1.7.1.tar.gz \ && chmod 777 libmaxminddb-1.7.1\ && cd libmaxminddb-1.7.1 \ && ./configure \ && make && make install \ && echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf \ && ldconfig
暴露端口
EXPOSE 80
启动 Nginx 服务器
CMD ["/usr/local/openresty/bin/openresty", "-g", "daemon off;"]