既有Nginx不停服重新动态编译增加http2.0模块

1、HTTP2.0

HTTP2.0相较于http1.x,大幅度的提升了web性能,在与http1.1完全语义兼容的基础上,进一步减少了网络延时。我们现在很多对外的网站都采用https,但是F12一下看多还是有不少应用还是用的http1.1协议,既然已经用了https,http2.0也要同步安排上
ps: http2.0只支持https

2、Nginx增加http2.0模块

很多小伙伴的Nginx都安装在Linux服务器,我们一般从官网下载的tar包,本地编译安装配置的nginx,我们这里就说一下如何在既有的Nginx基础上增加http2.0模块,新安装则直接在configure后参数上增加--with-http_v2_module即可,我们先来看一下当前nginx的已经编译的模块信息:

2.1、查看当前Nginx已编译的模块

$ ./nginx -V
nginx version: nginx/1.19.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx/ --user=www --group=www --prefix=/opt/nginx/ --with-http_ssl_module --with-http_stub_status_module

2.2、配置

很简单,把原来的arguments拷贝过来,增加--with-http_v2_module即可,执行命令如下:
./configure --prefix=/opt/nginx/ --user=www --group=www --prefix=/opt/nginx/ --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module

./configure --prefix=/opt/nginx/ --user=www --group=www --prefix=/opt/nginx/ --with-http_ssl_module --with-http_stub_status_module  --with-http_v2_module 

checking for OS
 + Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
checking for gcc -pipe switch ... found
  ……  
  ……
  ……
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/opt/nginx/"
  nginx binary file: "/opt/nginx//sbin/nginx"
  nginx modules path: "/opt/nginx//modules"
  nginx configuration prefix: "/opt/nginx//conf"
  nginx configuration file: "/opt/nginx//conf/nginx.conf"
  nginx pid file: "/opt/nginx//logs/nginx.pid"
  nginx error log file: "/opt/nginx//logs/error.log"
  nginx http access log file: "/opt/nginx//logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

2.3 编译和替换

执行make,千万不要 make&install,如果直接执行install会直接替换,make命令执行完成之后在编译目录objs文件下面有个nginx执行文件,此时我们把原来的sbin目录下nginx执行文件备份一下,讲新编译的nginx二进制文件拷贝到原执行文件的位置

mv nginx nginx.no.http2.xxxxxx
cp ../nginx-1.19.6/objs/nginx .

# 我们看一下新的编译文件模块信息
./nginx -V
nginx version: nginx/1.19.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx/ --user=www --group=www --prefix=/opt/nginx/ --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module

2.4 配置http2.0

在ssl配置后面增加http2配置即可
listen 443 ssl http2 ;
执行./nginx -s reload即可,这样我们就完成了在不停机的情况下动态编译添加nginx模块,如果需要安装其他模块同理可得。

参考链接:
nginx安装http2.0协议
HTTP/2 简介

posted @ 2021-02-05 15:38  蒲公英的狂想  阅读(391)  评论(0编辑  收藏  举报