通过新版宝塔安装的nginx,无法编译安装geoip2的解决办法

下一篇《nginx 配置geoip2 (以city为例)》https://www.jianshu.com/p/3387438696ab

1、首先查看nginx是否安装了编译的方法,注意V是大写(可以先通过宝塔编译安装,急速安装不可以编译)

# nginx -V

下面为查询结果

nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.1.1b  26 Feb 2019
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module --add-module=/www/server/nginx/src/ngx_http_geoip2_module

2、nginx的安装脚本路径:

/www/server/panel/install/nginx.sh
发现里面安装会先执行下面这段代码
    [ -f "/www/server/panel/install/nginx_prepare.sh" ] && . /www/server/panel/install/nginx_prepare.sh
    [ -f "/www/server/panel/install/nginx_configure.pl" ] && ADD_EXTENSION=$(cat /www/server/panel/install/nginx_configure.pl)
    if [ -f "/usr/local/lib/libjemalloc.so" ] && [ -z "${aarch64Check}" ];then
        jemallocLD="--with-ld-opt="-ljemalloc""

3、安装前配置

#新服务器记得先安装git
yum install git

3.1、第一种方法

3.1.1、在 /www/server/panel/install/nginx_prepare.sh (文件需要自己建)里添加第三方脚本代码(此脚本执行路径/www/server/nginx/src,安装时会清空,所以不可以提前下载到这里):

#!/bin/bash

#安装依赖库
yum install libmaxminddb-devel -y

#下载第三方扩展源码
git clone https://github.com/leev/ngx_http_geoip2_module.git
#如果下载时报错fatal: unable to access 'https://github.com/leev/ngx_http_geoip2_module.git/
则把 git clone https://github.com/leev/ngx_http_geoip2_module.git
改为 git clone git://github.com/leev/ngx_http_geoip2_module.git

3.1.2、(这一步是官方文档,可能是路径写死问题,找不到文件,所以建议直接执行3.2方法) 在 /www/server/panel/install/nginx_configure.pl (文件需要自己建)里添加add模块代码

--add-module=/www/server/nginx/src/ngx_http_geoip2_module

3.2、如果3.1.2添加方式安装报错,就删除3.1.2的文件,直接编辑nginx.sh文件:(大约220多行或者250多行,手动添加代码)

--add-module=${Setup_Path}/src/ngx_http_geoip2_module

    if [ "${WebDav_NGINX}" -ge "114" ] && [ "${WebDav_NGINX}" != "181" ];then   
        ENABLE_WEBDAV="--with-http_dav_module --add-module=${Setup_Path}/src/nginx-dav-ext-module --add-module=${Setup_Path}/src/ngx_http_geoip2_module"

3.3、根据这个思路,还有一个方法,不通过3.1,3.2的方式配置,而是:

直接先安装依赖,git下载geoip2到本地,然后在3.2这里加入
--add-module=本地路径/ngx_http_geoip2_module,执行下面的安装就行

上面3种配置方式都可以

4、然后再次通过ssh执行,我装的是1.18,可以改

sh /www/server/panel/install/nginx.sh install 1.18

如果报下面错误

./configure: error: the geoip2 module requires the maxminddb library

是因为依赖库没有安装成功,手动安装(可以提前装)

yum install libmaxminddb-devel

然后重新执行安装nginx

sh /www/server/panel/install/nginx.sh install 1.18

5、最后

nginx -V

查看第三方摸板编译成功

参考链接:
https://www.bt.cn/bbs/thread-16118-1-1.html
https://www.bt.cn/bbs/thread-37132-1-1.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容