非線上業務,純屬測試升級,線上業務不要采用此方法,可以采用官方推薦的平滑升級。
環境
Linux centos 7.7 nginx-1.10,2
nginx升級到最新nginx-1.16.1
一,官方下載最新源碼
wget http://nginx.org/download/nginx-1.16.1.tar.gz
二,停掉舊nginx服務
任意一種方法 kill or pkill or service stop ..... 都可以。
三,查看舊nginx舊編譯安裝參數,修改舊nginx
/usr/local/nginx/nginx -V
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.40 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/openssl-1.1.0f
mv /usr/local/nginx/nginx nginx.old
四,解壓,假設在/home/xxx/目錄
cd nginx-1.16.1
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.40 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/openssl-1.1.0f
make
只編譯不安裝
cp /home/xxx/nginx-1.16.1/objs/nginx /usr/local/nginx/nginx
五,測試加載配置文件
/usr/local/nginx/nginx -t -c nginx.conf
nginx -t -c nginx.conf
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
可以常事加載
六,查看新安裝當前版本
nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled
configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.40 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/openssl-1.1.0f
七,升級成功,啟動
service nginx start