Docker容器中的nginx平滑升级

【Docker容器中的nginx平滑升级】

nginx平滑升级

博主所在公司最近在扫描漏洞,很不幸,收到一个nginx安全漏洞,故写一下我是如何解决的吧,如果你不是部署在docker里也可以通用的。

漏洞描述

前置动作:【容器内部安装 nginx 1.24 所需依赖】

apk --update add gcc make g++ zlib-dev linux-headers pcre-dev openssl-dev
apk add gd-dev
apk add --no-cache geoip geoip-dev

开始升级

进入安装有nginx的docker容器

[root@localhost ~]# docker exec -it nginx bash

先看下当前nginx版本,很明显版本过低了,在0.6.18-1.20.0之间,升级它

[root@b656bb053512 /]# nginx -v nginx version: nginx/1.20.0

使用wget http://nginx.org/download/nginx-1.24.0.tar.gz把最新稳定版本下载下来,或者自己下载后传到服务器再使用docker cp到容器

解压

[root@b656bb053512 /]# tar xf nginx-1.24.0.tar.gz

进入 nginx-1.24.0

注意# 编译选项与旧版本的编译选项要一直,可以先用nginx -V 查看编译选项


nginx version: nginx/1.24.0
built by gcc 10.3.1 20211027 (Alpine 10.3.1_git20211027)
built with OpenSSL 1.1.1q  5 Jul 2022
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --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_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-http_v2_module

根据之前版本的编译选项,我们配置一下 ./configure --prefix=

上述完成以后,会在当前我解压缩nginx的objs下面产生一个nginx二进制文件

[root@b656bb053512 nginx-1.24.0]# cd objs/
[root@b656bb053512 objs]# ll
total 9308
-rw-r--r--. 1 root root   62235 Dec  7 09:04 Makefile
-rw-r--r--. 1 root root   19458 Dec  7 09:04 autoconf.err
-rwxr-xr-x. 1 root root 9307840 Dec  7 09:05 nginx
-rw-r--r--. 1 root root    5500 Dec  7 09:05 nginx.8
-rw-r--r--. 1 root root    9559 Dec  7 09:04 ngx_auto_config.h
-rw-r--r--. 1 root root     657 Dec  7 09:04 ngx_auto_headers.h
-rw-r--r--. 1 root root   10901 Dec  7 09:04 ngx_modules.c
-rw-r--r--. 1 root root   96976 Dec  7 09:05 ngx_modules.o
drwxr-xr-x. 9 root root      91 Dec  7 09:04 src
[root@b656bb053512 objs]# 

复制新版本的nginx二进制文件到就二进制文件路径,覆盖它,如果cp不行可用mv覆盖

[root@b656bb053512 objs]# cp nginx /usr/sbin/
[root@b656bb053512 objs]# nginx -v
nginx version: nginx/1.24.0

重启docker容器,重新启动nginx就可以了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小猪@笨笨

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

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

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

打赏作者

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

抵扣说明:

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

余额充值