1、下载相关包,需要和之前用到的依赖包保持一致 wget http://nginx.org/download/nginx-1.12.2.tar.gz wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/08a395c66e42.zip wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip 2、解压并备份之前的版本 tar xf nginx-1.12.2.tar.gz unzip master.zip unzip 08a395c66e42.zip cd /application/ cp -rp nginx1.12.1/ nginx.bak 3、查看当前版本使用的编译参数 ./nginx -V configure arguments: --user=nginx --group=nginx --prefix=/application/nginx1.12.1 --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../nginx-goodies-nginx-sticky-module-ng-08a395c66e42 --add-module=../nginx_upstream_check_module-master 4、编译安装 cd nginx-1.12.2 patch -p1 < ../nginx_upstream_check_module-master/check_1.12.1+.patch ./configure --user=nginx --group=nginx --prefix=/application/nginx1.12.1 --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../nginx-goodies-nginx-sticky-module-ng-08a395c66e42 --add-module=../nginx_upstream_check_module-master make #此步不要make install 5、拷贝新的启动文件 cd /application/nginx/sbin/ mv nginx nginx1_12_1 cp ~/nginx-1.12.2/objs/nginx . 6、检查是否成功,并平滑关闭 ./nginx -t nginx: the configuration file /application/nginx1.12.1/conf/nginx.conf syntax is ok nginx: configuration file /application/nginx1.12.1/conf/nginx.conf test is successful kill -USR2 `cat /application/nginx/logs/nginx.pid` kill -QUIT `cat /application/nginx/logs/nginx.pid.oldbin` 7、查看升级后的版本 ./nginx -v nginx version: nginx/1.12.2