yum 安装的 nginx 添加自定义模块后重新编译安装

总体思路:下载和当前系统相同版本的nginx,将要添加的模块在编译时添加编译,然后将编译好的nginx可执行文件替换原来/usr/sbin/nginx文件

1. 查看nginx版本信息

root@www:~# nginx -V
nginx version: nginx/1.14.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug

2. 对现有的nignx进行备份

mv /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx /etc/nginx.bak

3. 下载和此版本相同的nginx源码包并解压

wget http://nginx.org/download/nginx-1.XX.X.tar.gz
tar -xvzf nginx-1.XX.X.tar.gz

4. 更新一下相关依赖包

yum -y install libxml2 libxml2-devel libxslt-devel gd gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data 
yum -y install --skip-broken gcc gcc-c++ autoconf automake gperftools 
yum -y install --skip-broken zlib zlib-devel openssl-devel pcre-devel
yum -y install pcre*

5. 停止nginx服务

systemctl stop nginx

6. 进入新下载的nginx目录,进行编译,添加模块为 with-http_geoip_module

cd ngxin-1.XX.X
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-http_geoip_module

make #千万不要make install

7. 测试是否编译成功
nginx -t

8. 替换使用新的nginx
cp /usr/sbin/nginx /usr/sbin/nginx-bak
cp ./objs/nginx /usr/sbin/nginx

9. 重启nginx
systemctl start nginx

其间可能遇到的问题及相应的解决方案:

nginx安装error: perl module ExtUtils::Embed is required-IDC资讯中心编译安装nginx的时候–with-http_perl_module 这个参数,编译时出现如下错误:error: perl module ExtUtils::Embed is required解决办法安装依赖:yum -y install perl-devel perl-ExtUtils-Embedhttp://www.west999.com/www/info/88675-1.htm/configure: error: the HTTP XSLT module requires the libxml2/libxslt_小白正在飞的博客-CSDN博客安装nginx 报错/configure: error: the HTTP XSLT module requires the libxml2/libxsltyum -y install libxml2 libxml2-devyum -y install libxslt-develhttps://blog.csdn.net/ukgikgb/article/details/106923724安装nginx报错,make命令error: ‘struct crypt_data’ has no member named ‘current_salt’ cd.current_salt[0_Jchgen的博客-CSDN博客被坑坏了!第一步:vim src/os/unix/ngx_user.c把cd这一行注释掉。第二步:如果还不行的话 vim objs/Makefile把这句中的 - -Werror删掉。然后再进行make就可以了。https://blog.csdn.net/mercycpp/article/details/121629994

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戴国进

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值