应用商店的openresty能否再安装geoip2模块

希望通过geoip2实现 限制不同地区用户,需要精确到省市,现在内置了geoip模块,想问一下如果再添加geoip2模块是不是会出现异常,如果会出现异常的话,要怎么做兼容呢,一方面希望能够使用应用商店的openresty 另一方面 希望可以实现限制地区访问的话需要怎么做

我们没有修改过 Openresty 的依赖,我们的地区访问限制是通过 Lua 实现的,由于精度问题,现在暂时只能精确到省,如果你想添加 geo 模块,需要自行编译 Openresty 镜像

我看了一下openresty容器的参数,如果我修改容器内的标签里的这一段参数,原有的新建网站openresty相关功能是否会受到影响?

resty_eval_post_download_pre_configure=
resty_image_base=ubuntu
resty_pcre_options=--with-pcre-jit
com.docker.compose.container-number=1
com.docker.compose.image=sha256:77b80412c8d54159d31e837392a15bfb3027d285d20e05e39dc8eb574c90904b
com.docker.compose.version=2.26.1
resty_add_package_builddeps=
com.docker.compose.project.working_dir=/opt/1panel/apps/openresty/openresty
resty_config_options_more=
resty_openssl_version=1.1.1w
resty_pcre_build_options=--enable-jit
com.docker.compose.project.config_files=/opt/1panel/apps/openresty/openresty/docker-compose.yml
org.opencontainers.image.ref.name=ubuntu
resty_image_tag=focal
com.docker.compose.oneoff=False
resty_config_deps=--with-pcre     --with-cc-opt='-DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl/include'     --with-ld-opt='-L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl/lib -Wl,-rpath,/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib'     
resty_pcre_sha256=4e6ce03e0336e8b4a3d6c2b70b1c5e18590a5673a98186da90d4f33c23defc09
resty_pcre_version=8.45
com.docker.compose.project=openresty
org.opencontainers.image.version=20.04
resty_add_package_rundeps=
resty_eval_pre_configure=
resty_openssl_patch_version=1.1.1f
resty_luajit_options=--with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT'
resty_openssl_url_base=https://www.openssl.org/source
com.docker.compose.config-hash=82297f862c7046684e357078ccfcb95e282269b1edb6eaed45bf3c04d5a7a763
com.docker.compose.depends_on=
maintainer=Evan Wies <evan@neomantra.net>
resty_eval_post_make=
resty_version=1.21.4.3
com.docker.compose.service=openresty
createdBy=Apps
resty_config_options=    --with-compat     --with-file-aio     --with-http_addition_module     --with-http_auth_request_module     --with-http_dav_module     --with-http_flv_module     --with-http_geoip_module=dynamic     --with-http_gunzip_module     --with-http_gzip_static_module     --with-http_image_filter_module=dynamic     --with-http_mp4_module     --with-http_random_index_module     --with-http_realip_module     --with-http_secure_link_module     --with-http_slice_module     --with-http_ssl_module     --with-http_stub_status_module     --with-http_sub_module     --with-http_v2_module     --with-http_xslt_module=dynamic     --with-ipv6     --with-mail     --with-mail_ssl_module     --with-md5-asm     --with-sha1-asm     --with-stream     --with-stream_ssl_module     --with-threads     
resty_luarocks_version=3.9.2

你可以试一下

1 个赞

仔细看了一下如果自带的就可以精确到省,请问怎么在配置文件中调用,比方说我要将上海地区的请求转发至shanghai.xxx.com这个域名的指向的服务器,这样下次升级容器就不会覆盖之前的 :rofl:

这个需求暂时没办法满足

location / {
    default_type text/plain;
    content_by_lua_block {
                local maxminddb = require "resty.maxminddb"
                
                local db, err = maxminddb.new("/usr/local/openresty/1pwaf/data/geo/GeoIP.mmdb")
                if not db then
                    ngx.say("failed to open mmdb: ", err)
                    return
                end

                local ip = ngx.var.remote_addr
                
                local res, err = db:lookup(ip, "en")
                if not res then
                    ngx.say("failed to lookup ip: ", err)
                    return
                end

                local country = res.country and res.country.names and res.country.names.en or "unknown"
                local region = res.subdivisions and res.subdivisions[1] and res.subdivisions[1].names and res.subdivisions[1].names.en or "unknown"
                local city = res.city and res.city.names and res.city.names.en or "unknown"

                ngx.say("Country: ", country)
                ngx.say("Region: ", region)
                ngx.say("City: ", city)
            }
        }
}

请问为什么我自己写了段测试用的lua脚本在网页端保存的时候提示我无权限操作