多彩编程 多彩编程MZPH · CODE BLOG
ARTICLE DETAIL

文章详情

深耕前端与后端开发技术的一线实战笔记与踩坑复盘。

nginx旧版本直接升级到最新1.30.4--亲测图文详解

nginx旧版本直接升级到最新1.30.4--亲测图文详解 问题最近nginx有漏洞需要升级到最新版本 Map 时的缓冲区溢出漏洞CVE-2026-42533F5 NGINX Plus和F5 NGINX Open Source 缓冲区错误漏洞(CVE-2026-32647)解决升级到最新版本升级Alternative downloads | Ubuntunginx 升级到最新版本打开官网最新稳定版本是1.30.4已发布nginx-1.30.4稳定版和nginx-1.31.3主线版本 修复了使用正则表达式 Map 时的缓冲区溢出漏洞CVE-2026-42533、使用 ngx_http_slice_module 时的内存泄露漏洞CVE-2026-60005以及使用 ngx_http_ssi_module 时的释放后使用漏洞CVE-2026-56434。一、下载wget https://nginx.org/download/nginx-1.30.4.tar.gz解压tar xvf nginx-1.30.4.tar.gz安装依赖要是之前安装过就不需要安装了。yum -y install gcc gcc-c autoconf automake make pcre-devel zlib-devel openssl openssl-devel进到目录编译cd nginx-1.30.4 ./configure --prefix/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre --with-http_gzip_static_module --with-http_mp4_module --with-http_flv_module --with-http_realip_module --with-stream二、升级的也是直接执行下面命令就可以/usr/local/nginx/sbin/nginx -s stop #如果是旧的nginx 停掉直接编译新的 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old #备份旧的 make -j$(nproc) make install /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx -s reload /usr/local/nginx/sbin/nginx -V可以看到就升级好了。剩下的其他配置如果是升级就完成了升级。-------------------------------------------------------------------------------------------------------------------如果是第一次安装添加环境变量echo export PATH$PATH:/usr/local/nginx/sbin/ /etc/profile source /etc/profile添加配置client_max_body_size 100M; client_body_buffer_size 100M; server_tokens off; #关闭版本显示生成服务启动脚本vim /etc/init.d/nginx#!/bin/bash # chkconfig: - 99 2 # description: Nginx Service Control Script PROG/usr/local/nginx/sbin/nginx PIDF/usr/local/nginx/logs/nginx.pid case $1 in start) $PROG ;; stop) kill -3 $(cat $PIDF) ;; restart) $0 stop /dev/null if [ $? -ne 0 ] ; then continue ; fi $0 start ;; reload) kill -1 $(cat $PIDF) ;; *) echo Userage: $0 { start | stop | restart | reload } exit 1 esac exit 0chmod x /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on chkconfig --list设置图片js 缓存server { listen 80; server_name example.com; # 替换为你的域名或IP root /var/www/html; # 静态文件根目录 index index.html; # 默认不缓存 HTML 文件确保内容实时更新 location ~* \.html?$ { expires -1; add_header Cache-Control no-store, no-cache, must-revalidate; } # 图片缓存jpg、jpeg、png、gif、ico、svg、webp location ~* \.(jpg|jpeg|png|gif|ico|svg|webp)$ { expires 30d; # 缓存30天 access_log off; # 可选关闭图片访问日志 add_header Cache-Control public, immutable; } # JS 和 CSS 缓存 location ~* \.(js|css)$ { expires 7d; # 缓存7天 add_header Cache-Control public, immutable; } # 其他静态资源字体、音视频等 location ~* \.(woff2?|ttf|otf|eot|mp4|pdf)$ { expires 30d; add_header Cache-Control public, immutable; } }
返回列表