升级nginx以支持http2的方法
本篇文章主要介绍了升级nginx以支持http2的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
本文介绍了升级nginx以支持http2的方法,分享给大家,具体如下:
一键升级脚本
https://github.com/whisshe/upHttp2.git
HTTP/2 的优势
相比 HTTP/1.x,HTTP/2 在底层传输做了很大的改动和优化:
HTTP/2 采用二进制格式传输数据,而非 HTTP/1.x 的文本格式。二进制格式在协议的解析和优化扩展上带来更多的优势和可能。
HTTP/2 对消息头采用 HPACK 进行压缩传输,能够节省消息头占用的网络的流量。而 HTTP/1.x 每次请求,都会携带大量冗余头信息,浪费了很多带宽资源。头压缩能够很好的解决该问题。
多路复用,直白的说就是所有的请求都是通过一个 TCP 连接并发完成。HTTP/1.x 虽然通过 pipeline 也能并发请求,但是多个请求之间的响应会被阻塞的,所以 pipeline 至今也没有被普及应用,而 HTTP/2 做到了真正的并发请求。同时,流还支持优先级和流量控制。
Server Push:服务端能够更快的把资源推送给客户端。例如服务端可以主动把 JS 和 CSS 文件推送给客户端,而不需要客户端解析 HTML 再发送这些请求。当客户端需要的时候,它已经在客户端了。
升级HTTP2必要条件
1.10.0版本以上的nginx基于1.0.2以上版本的openssl编译
必须支持https
软件安装位置
openssl
1、编译位置
/usr/local/openssl
2、软链接位置
/usr/bin/openssl
/usr/include/openssl
nginx
1、编译及配置文件位置
/etc/nginx
升级所有游戏服务器的nginx和OpenSSL
升级openssl
1、将旧版本的openssl备份
1
2
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
2、下载1.1版本的openssl,并解压编译
1
2
3
4
5
6
7
8
9
10
11
wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz
tar zxvf openssl-1.1.0g.tar.gz
cd openssl-1.1.0g/
./config --prefix=http://www.zzvips.com/usr/local/openssl shared zlib
make depend
make && make install
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl(首选)
cd /usr/local/openssl/lib
ln -s libssl.so.1.1 libcrypto.so.1.1 /lib/x86_64-linux-gnu/
echo /usr/local/openssl/lib >> /etc/ld.so.conf
3、验证openssl版本信息
1
2
3
4
openssl version
if [[ `openssl version |awk '{print $2}'` == 1.1.0g ]];then
echo ok
fi
nginx升级(源码编译)
原配置文件不会丢失
1、下载源码包
1
wget http://nginx.org/download/nginx-1.12.2.tar.gz
2、解压编译安装
编译安装 nginx 时,--with-openssl 参数默认只支持OpenSSL的源代码,不支持已编译好的 OpenSSL。可以在nginx的解压目录下修改auto/lib/openssl/conf
sed "s/.openssl\///" c
将文件中的.openssl去掉,就可以支持编译之后的openssl路径了
1
2
3
4
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
正式编译
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
./configure --prefix=http://www.zzvips.com/etc/nginx \
--sbin-path=http://www.zzvips.com/usr/sbin/nginx \
--conf-path=http://www.zzvips.com/etc/nginx/nginx.conf \
--error-log-path=http://www.zzvips.com/var/log/nginx/error.log \
--http-log-path=http://www.zzvips.com/var/log/nginx/access.log \
--pid-path=http://www.zzvips.com/var/run/nginx.pid \
--lock-path=http://www.zzvips.com/var/run/nginx.lock \
--http-client-body-temp-path=http://www.zzvips.com/var/cache/nginx/client_temp \
--http-proxy-temp-path=http://www.zzvips.com/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=http://www.zzvips.com/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=http://www.zzvips.com/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=http://www.zzvips.com/var/cache/nginx/scgi_temp \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-openssl=http://www.zzvips.com/usr/local/openssl
修改nginx配置
1
listen 443 ssl http2;
出现的问题及解决
centos7下openssl version报错openssl: error while loading shared libraries: libssl.so.1.1
1
2
echo /usr/local/openssl/lib >> /etc/ld.so.conf # 将openssl编译路径的lib库加入到/etc/ld.so.conf
ldconfig -v|grep libssl # 检查是否添加成功
nginx重启出现错误,nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed
1
2
3
ls -l /var/cache/nginx/client_temp#检查该文件夹是否存在和文件夹的权限
mkdir -p /var/cache/nginx/client_temp #文件夹不存在则生成文件夹
chown -R www-data:www-data /var/cache/nginx/client_temp # 将文件夹所有者和组改为nginx的运行用户,具体见nginx.conf
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/server/nginx/12123.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
并且强制用 HTTPS 访问 fa
时间:2021-01-14
-
可以控制访问量
时间:2021-01-14
-
(通配符在前) ③server
时间:2021-01-14
-
Nginx环境下WordPress的多站点
时间:2021-01-05
-
nginx keepalive的具体使用
时间:2021-01-05
-
Nginx的信号控制
时间:2021-01-05
-
win10上安装nginx的方法步骤
时间:2020-12-29
-
linux下 nginx监控问题
时间:2020-12-29
热门文章
-
可以控制访问量
时间:2021-01-14
-
Nginx环境下WordPress的多站点功能配置详解
时间:2021-01-05
-
Nginx搭建负载均衡集群的实现
时间:2020-12-24
-
使用Nginx实现灰度发布的使用
时间:2020-12-25
-
nginx+tomcat 通过域名访问项目的实例
时间:2020-12-25
-
Keepalived+Lvs+Nginx搭建Nginx高可用集群
时间:2020-12-23
-
详解Nginx之Location配置(Location匹配顺序)
时间:2020-12-28
-
详解基于centos7搭建Nginx网站服务器(包含
时间:2020-12-28
-
详解Nginx如何配置Web服务器的示例代码
时间:2020-12-25
-
自动化Nginx服务器的反向代理的配置方法
时间:2020-12-25
