前言
关于漏洞扫描Nginx安全漏洞的修复。
服务器漏洞扫描中扫出了Nginx的安全漏洞,Nginx 安全漏洞(CVE-2021-23017)和Nginx 环境问题漏洞(CVE-2019-20372),受影响版本为0.6.18-1.20.0;给出解决办法为升级补丁修复,由于漏洞较多考虑平滑升级。
一、linux下载
官方下载渠道下载1.20.0以上版本的linux。下载地址:
http://nginx.org/en/download.html
我使用的服务器是linux系统,推荐下载官网Stable version的1.22.0版本。
二、平滑升级
1.查看Nginx版本
代码如下(示例):
查看Nginx进程
ps -ef | grep Nginx
找到Nginx 二进制可执行文件后,查看Nginx版本,可以看到当前版本为1.18.0:
/usr/sbin/Nginx -V
Nginx version: Nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/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 --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --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-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,Now -pie'
将Nginx 二进制可执行文件先备份,出错了好回退。
mv /usr/sbin/Nginx /usr/sbin/Nginx-1.18
2.Nginx上传解压,文件替换
将下载的压缩包上传至linux服务器,上传位置没有要求,我这里上传解压到了旧版linux的同级目录:
解压压缩文件
[root@i]# cd etc/
[root@i etc]# tar xf Nginx-1.22.0.tar.gz
进入解压后的文件夹内,使用configure 进行配置,configure 后跟的参数是第一步复制的,由于上个版本部署的Nginx改了配置文件及日志的位置,此命令仅供参考,路径由实际情况自行修改:
[root@i etc]# cd Nginx-1.22.0
[root@i Nginx-1.22.0]# ./configure --prefix=/etc/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 --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --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-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,Now -pie'
简单配置的话可适用此命令:
[root@i Nginx-1.22.0]# ./configure --prefix=/etc/Nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module
上一步完成后make:
[root@i Nginx-1.22.0]# make
此时配置完成,将新的Nginx 二进制可执行文件,放到原来的目录下,注意1.22.0版本的Nginx文件在objs目录下,不在sbin目录里:
[root@i Nginx-1.22.0]# cp objs/Nginx /usr/sbin/Nginx
3.查看升级是否成功
出现test is successful说明Nginx正常运行:
[root@i Nginx-1.22.0]# /usr/sbin/Nginx -t
Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
Nginx: configuration file /etc/Nginx/Nginx.conf test is successful
[root@i Nginx-1.22.0]# /usr/sbin/Nginx -V
Nginx version: Nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/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 --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --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-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,Now -pie'
总结
以上就是对Nginx 安全漏洞进行处理平滑升级的内容,本文仅仅简单记录了自己工作中处理的问题,不一定适用于所有情况,仅供大家参考。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。