preface

Nginx has been running version 1.8.0, which does not support HTTP2. In order to use http2’s multiplexing and header compression features to speed up page access, nginx needs to be upgraded to support HTTP2.

Tip: Strictly speaking, multiplexing is only a solution to the problem of TCP connection channel limit when loading six resources in the same domain on a page. As a result, a key resource must wait for the first six resources to be loaded before the page is long. If you already have a resource domain, such as A CDN, then multiplexing may not be so obvious, but multiplexing can be useful for handling three-way + TLS handshakes caused by establishing multiple TCP links.

upgrade

Environment: Centos 7.6.1310

The installation

Configure the nginx installation source on yum

$ vi /etc/yum.repos.d/nginx.repo
Copy the code

Content as follows:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
Copy the code

Yum install nginx yum clean all && yum update nginx

  1. yum clean allClearing the YUM Cache
  2. # nginx = /etc/nginx # nginx = /etc/nginx # nginx = /etc/nginx # nginxyum update nginxIt will not take effect because it is not considered installed. Yum yum yum yum yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum Yum

Soft connection

Nginx does not automatically set the global nginx command for you.

$ ln -s /usr/sbin/nginx /use/local/bin
Copy the code

detection

$ 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'Copy the code

The –with-http_v2_module module already exists, indicating that http2 is supported

The migration

There are two levels of migration: simple migration and full migration. Simple migration is to directly copy the old nginx conf file to the new nginx directory and replace it. The old nginx configuration path is absolute and will not be changed when the main conf file is moved.

Of course, this is not the final solution, although we can run after the last step, but we do not want to maintain two nginx directories, because all the associated conf is still under the old nginx, we would have to migrate all the HTML files and conf files. After the migration, the nginx configuration of the HTML directory will definitely change, which will need to be replaced in batches.

$ cp old/html new/html
$ cp old/conf new/conf
Copy the code
$find to replace the content directory - the name "*. Conf" | xargs perl - PI - e 's | | new path to the old | g'Copy the code

Find the.conf file in the path and replace the text.

Checks whether the configuration can be started

nginx -t
Copy the code

Close the original nginx

/data/nginx/sbin/nginx -s quit
Copy the code

Start a new Nginx

nginx
Copy the code

With that out of the way, it’s still a bit of a hassle to modify the Jenkins deployment path, but it’s worth it to support HTTP2.