Home >Operation and Maintenance >Nginx >How to upgrade nginx version without affecting business
This article introduces the method of smoothly upgrading nginx installed with yum. If the original nginx was compiled and installed, you should pay attention to your actual configuration when upgrading.
(Recommended tutorial: nginx tutorial)
1. Check the nginx version and existing configuration installed by yum
First record the previous configuration,
nginx -V
nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/share/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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ --with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’ --add-module=/root/nginx-rtmp-module
configure arguments will be used later: The following is the existing configuration of nginx
2. Download the required new version of nginx source code package
wget http://nginx.org/download/nginx-1.14.2.tar.gz
3. Back up the original nginx important files (for safety)
mv /usr/sbin/nginx /usr/sbin/nginx.back cp -rf /etc/nginx /etc/nginx.back
4. Compile
Adopt the configuration found earlier. If there are new modules to be added, you can also add them
tar xf nginx-1.14.2.tar.gz cd nginx-1.14.2
./configure --prefix=/usr/share/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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ --with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’ --add-module=/root/nginx-rtmp-module
5. make
Since nginx already exists, make install cannot be executed, otherwise the previous configuration file and content will be overwritten
make cp objs/nginx /usr/sbin/nginx
6. Check whether it is successful
/usr/sbin/nginx -t
7. Smooth switching
Note: Find the location of your pid file based on your actual compiled configuration content. The original nginx in this article is installed by yum, so it is under /var/run.
In fact, you can also use make update to upgrade in the nginx-1.14.2 directory. In order to avoid problems, it is recommended to handle it manually
kill -USR2 `cat /var/run/nginx.pid` 将旧版本Nginx的主进程将重命名为nginx.pid.oldbin,并执行新版本的Nginx可执行程序,启动新的主进程和新的工作进程,再次生成新的nginx.pid文件 kill -WINCH `cat /var/run/nginx.pid.oldbin` 平缓停止worker process(此步骤可省略) kill -QUIT `cat /var/run/nginx.pid.oldbin` 平缓停止旧的Nginx服务进程
8. View
Supplement to the article:
Signals supported by Nginx
can be used to control Nginx activities
TERM, INT - quick shutdown
QUIT Smooth shutdown
HUP Smooth restart, reload configuration file
USR1 Reopen log file
USR2 Smooth upgrade of executable program
WINCH Smooth Close worker process
The above is the detailed content of How to upgrade nginx version without affecting business. For more information, please follow other related articles on the PHP Chinese website!