记一次 nginx 版本升级
前言
由于公司服务器 nginx 一直用的是 1.8.0 版本,该版本不支持 http2,为使用 http2 的多路复用和头部压缩特性,提升页面访问速度,所以需要升级 nginx 至可以支持 http2。
Tip:严格来讲多路复用仅在解决某个页面一起加载 6 个同域资源会遇到的 tcp 链接通道数限制,导致某关键资源需要等前面 6 个先加载完从而页面空白长问题。假如你已经通过资源分域,比如 CDN,那么可能多路复用的作用不是那么明显,但是多路复用在解决建立多个 tcp 链接,导致的三次握手 TLS 握手上作用还是明显。
升级
环境:Centos 7.6.1310
安装
配置 yum 上的 nginx 安装源
$ vi /etc/yum.repos.d/nginx.repo
内容为:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
假如之前安装过,那么直接 yum clean all && yum update nginx
,没有安装过就执行 yum install nginx
。
yum clean all
清除 yum 缓存- 这里有个坑,之前安装过不代表说本机有 nginx 就是安装过,而是之前用 yum 安装过,因为 yum 安装的 nginx 文件夹放在 /etc/nginx 下,假如本机的 nginx 不在该目录下,那么
yum update nginx
是不会生效的,因为被认为没有安装过。我也就是该情况,虚拟机自带的 nginx 是实例化虚拟机自带的,跟 yum 没有关系,安装之后在本机就相当多出来另外一个 nginx,所以一下要涉及 nginx 配置文件的迁移。
软连接
yum 安装的 nginx 不会自动给你设置全局 nginx 命令,为了方便使用,需要建立软连接:
$ ln -s /usr/sbin/nginx /use/local/bin
检测
$ nginx -V
nginx version: nginx/1.21.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
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'
已经看到有 --with-http_v2_module 模块,代表已经支持 http2
迁移
迁移有两种程度,简单迁移和完整迁移,简单迁移就是直接将老的 nginx 的 nginx.conf 直接复制到新的 nginx 目录下替换即可,因为老的 nginx 下配置的路径都是绝对路径,不会因为主 conf 被移动而改变。
当然这不是最终的方案,虽然说上一步之后就可以跑了,但是我们不希望维护两份 nginx 目录,因为所有关联的 conf 还是在 老的 nginx 下, 那么我们就必须要将所有的 html 文件和 conf 进行迁移,迁移之后 nginx 配置的 html 目录肯定也是要发生变化的,这个时候需要批量替换。
$ cp old/html new/html
$ cp old/conf new/conf
$ find 要替换内容的目录 -name "*.conf" | xargs perl -pi -e 's|老的路径|新的路径|g'
在路径下找到后缀为 .conf 的文件,替换文本内容。
检测配置是否可以启动
nginx -t
关闭原来的 nginx
/data/nginx/sbin/nginx -s quit
启动新的 nginx
nginx
到此告一段落,后续还要去修改 Jenkins 上的部署路径,还是比较麻烦,但是为了支持 http2 也是值得的。
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhfgaehi
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13