nginx升级
nginx升级
1.官网下载最新的安装包
下载地址:https://nginx.org/en/download.html
本次使用:nginx-1.28.0
2.备份文件
# 查找nginx主程序
whereis nginx
# 这里查到文件是在/usr/sbin/nginx,其他两个都是目录
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
# 备份/usr/sbin/nginx
cp /usr/sbin/nginx /usr/sbin/nginx.old
3.上传并解压文件
#上传到home目录
cd /home
tar -zxvf nginx-1.28.0.tar.gz
3.参数配置和安装依赖
# 查看版本号
nginx -v
# 查看版本信息
nginx -V
# 版本信息如下
nginx version: nginx/1.10.3 (Ubuntu)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads
# 参数配置
cd /home/nginx-1.28.0/
# 带上原有参数
./configure --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads
此时可能会有一些报错,大多是一些依赖不存在,根据具体报错内容安装对应的依赖即可。每台服务器情况可能都不一样,此处列举一些如下:
# 报错1
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
# 解决1
sudo apt-get install libpcre3 libpcre3-dev
#报错2
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
#解决2
sudo apt-get install zlib1g-dev
如果服务器没有网络,可以使用挂载本地镜像的方式更新依赖,或者去对应版本镜像中拷贝对应安装包安装
4.编译和安装
# 进行编译操作
cd /home/nginx-1.28.0/
make
# 编译完成objs目录会生成nginx主程序文件
/home/nginx-1.28.0/objs
./nginx -v
5.验证和升级
# 编译完成objs目录会生成nginx主程序文件
cd /home/nginx-1.28.0/objs
./nginx -V
./ngixn -t
# 测试运行成功后覆盖原件或者建立软链接
cp /home/nginx-1.28.0/objs/nginx /usr/sbin/nginx
# 可能会提示文件繁忙,把nginx关闭在复制即可
service nginx stop
cp /home/nginx-1.28.0/objs/nginx /usr/sbin/nginx
service nginx start
从一个菜鸟进阶成一个老菜鸟

浙公网安备 33010602011771号