1、查看目前nginx版本及./configure参数
nginx -V
示例:
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,-z,now -pie'
2、预编译新版nginx,如果需要可指定openssl路径,示例:--with-openssl=/usr/local/openssl/openssl-1.1.1g
cd /opt/nginx-1.20.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,-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,-z,now -pie'
3、可能的编译错误
OpenSsl lib not found
解决方案:
(1)查看是否安装OpenSsl lib
openssl version
(2)若未安装,则进行安装,若已安装但与nginx编译配置文件中指定的路径不匹配,则将OpenSsl lib拷过去(或使用--with-openssl=/home/nginx/openssl-1.1.1q/ssl指定ssl源码目录,必须是源码目录,源码版本最好与openssl version显示版本一致),重新编译
示例:cp -r /usr/local/ssl/lib /opt/local/
4、执行编译、安装nginx
(1)make && make install
(2)echo $?
结果为0,表示没有错误
5、将新的nginx可执行文件替换旧版nginx可执行文件
(1)切换到nginx可执行文件目录:cd /usr/sbin/
(2)备份旧版:mv nginx nginx-1.14.2
(3)将新版文件拷贝过来:cp /opt/sbin_nginx/nginx ./
(4)最新版本是cp xxx/objs/nginx /usr/sbin/
6、进行平滑升级
(1)ps -ef|grep nginx
(2)kill -USR2 447
(3)kill -WINCH 447
(4)前三步可用此命令代替:make upgrade
(5)查看当前nginx版本:nginx -V 并 通过浏览器访问,查看请求头中的nginx版本
(6)确认一切无误后,关闭旧版master进程:kill -QUIT old_master_PID