Nginx 学习笔记(二)Web 服务启用 HTTP/2
个人网站提升为HTTP2.0协议,加速访问
一、条件
1、openssl的版本必须在1.0.2e及以上
2、nginx的版本必须在1.9.5以上
二、编译安装
1、openssl 编译安装
(1)开始
wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2j.tar.gz
tar zxvf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j
./config shared zlib
make && make install
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig -v
注:
(2)查看openssl版本
www@TinywanAliYun: openssl version
OpenSSL 1.0.2j Sep
232
2、重新编译Openresty
(1)本次将下载最新版本:openresty-1.13.6.1.tar.gz
wget https://openresty.org/download/openresty-1.13.6.1.tar.gz
tar zxvf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1/
(2)修改加载openssl 方式
vim /home/www/build/openresty-1.13.6.1/bundle/nginx-1.13./auto/lib/openssl/conf
vim /home/www/build/openresty-1.13.6.1/build/nginx-1.13./auto/lib/openssl/conf
修改后内容,注意:这里是修改为两个不同目录的openssl的配置文件
# 修改前:
#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" # 修改前:
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
我这里是直接注释掉,添加新的

(3)重新编译Openresty ,添加–with-openssl参数
./configure \
--user=www \
--group=www \
--prefix=/usr/local/openresty \
--with-luajit \
--with-http_v2_module \
--with-http_realip_module \
--with-http_mp4_module \
--with-stream \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-openssl=/usr/local/ssl \
--with-openssl-opt="enable-tlsext" \
--without-http_redis2_module \
--with-http_iconv_module \
--with-http_stub_status_module \
--with-http_xslt_module \
--add-dynamic-module=/home/www/build/nginx-ts-module \
--add-dynamic-module=/home/www/build/nginx-rtmp-module \
--add-dynamic-module=/home/www/build/nginx-module-vts \
--add-module=/home/www/build/ngx_cache_purge-2.3 \
...
...
make
注意:这里只要编译就可以啦,没必要make install (会覆盖原来已经安装好的内容)
(4)修改Nginx 二进制文件,如果Nginx服务正在运行,必须停止,否则无法覆盖
首先备份二进制文件一份:
cp /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginx.old
覆盖旧二进制文件
cp -f /home/www/build/openresty-1.13.6.1/build/nginx-1.13./objs/nginx /usr/local/openresty/nginx/sbin/nginx
如果动态编译了其他模块或者同一个模块的不同版本,则同上一并复制过去
cp -f /home/www/build/openresty-1.13.6.1/build/nginx-1.13./objs/ngx_rtmp_module.so /usr/local/openresty/nginx/modules/ngx_rtmp_module.so cp -f /home/www/build/openresty-1.13.6.1/build/nginx-1.13./objs/ngx_http_ts_module.so /usr/local/openresty/nginx/modules/ngx_http_ts_module.so cp -f /home/www/build/openresty-1.13.6.1/build/nginx-1.13./objs/ngx_http_vhost_traffic_status_module.so /usr/local/openresty/nginx/modules/ngx_http_vhost_traffic_status_module.so
(5)重启服务,查看配置信息
sudo systemctl start nginx
配置详情
www@TinywanAliYun:~/build/openresty-1.13.6.1/build/nginx-1.13./objs$ sudo /usr/local/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.13.6.1
built by gcc 5.4. (Ubuntu 5.4.-6ubuntu1~16.04.)
built with OpenSSL 1.0.2j Sep
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.
--with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --user=www --group=www --with-http_v2_module --with-http_realip_module
--with-http_mp4_module --with-stream --with-http_ssl_module --with-openssl=/usr/local/ssl
--with-openssl-opt=enable-tlsext --with-http_stub_status_module --with-http_xslt_module
--add-dynamic-module=/home/www/build/nginx-ts-module --add-dynamic-module=/home/www/build/nginx-rtmp-module
--add-dynamic-module=/home/www/build/nginx-module-vts
--add-dynamic-module=/home/www/build/ngx_cache_purge-2.3
--with-stream --with-stream_ssl_module --user=www --group=www --with-http_v2_module
--with-http_ssl_module --with-openssl=/usr/local/ssl --with-openssl-opt=enable-tlsext --with-http_stub_status_module --with-http_xslt_module
--add-dynamic-module=/home/www/build/nginx-ts-module
--add-dynamic-module=/home/www/build/nginx-rtmp-module
--add-dynamic-module=/home/www/build/nginx-module-vts
--add-dynamic-module=/home/www/build/ngx_cache_purge-2.3
--with-stream --with-stream_ssl_module
三、配置Nginx.conf
server {
listen ssl http2;
server_name www.tinywan.com;
set $root_path /home/www;
root $root_path;
ssl on;
ssl_certificate /etc/letsencrypt/live/www.tinywan.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.tinywan.com//privkey.pem;
server_tokens off;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$ last;
break;
}
}
}
四、测试
1、测试工具,Chrome 的 Net-internals 工具 (Chrome 中通过 chrome://net-internals/#http2 可以访问)
2、测试结果



浏览器Header 请求头变化

五、参考文章
3、HTTP协议简介
4、nginx的http2.0性能太逆天了,HTTPS网站性能优化
9、[翻译]Dropbox Web 服务启用 HTTP/2:经验和观察
Nginx 学习笔记(二)Web 服务启用 HTTP/2的更多相关文章
- Netty学习笔记(二) 实现服务端和客户端
在Netty学习笔记(一) 实现DISCARD服务中,我们使用Netty和Python实现了简单的丢弃DISCARD服务,这篇,我们使用Netty实现服务端和客户端交互的需求. 前置工作 开发环境 J ...
- nginx学习笔记二
一,nginx架构在Linux系统中以daemon(守护进程)的方式在后台运行,后台进程包含一个master进程和多个worker进程(多进程的工作方式) master进程 | 信号 | | ---- ...
- Nginx学习笔记二基本配置
1.Nginx的配置文件默认在Nginx程序安装目录的conf二级目录下,主配置文件为nginx.conf.假设您的Nginx安装 在/usr/local/webserver/nginx/目录下,那么 ...
- nginx学习笔记(二)
nginx变量 Nginx 变量值容器的生命期是与当前正在处理的请求绑定的,而与 location 无关. 通过 set 指令隐式创建的 Nginx 变量.这些变量我们一般称为"用户自定义变 ...
- dubbo学习笔记二(服务调用)
项目结构 代码示例 由于之前的IEchoService 的一个方法只是在服务端控制台打印,不便在浏览器测试,所以新添加的方法 api和服务端代码变更 public interface IEchoSer ...
- amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules
amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules 一.总结 1.见名知意:见那些class名字知意,见函数名知意,见文件名知意 例如(HISTORY.md Web 组件更新历史 ...
- amazeui学习笔记二(进阶开发2)--Web组件简介Web Component
amazeui学习笔记二(进阶开发2)--Web组件简介Web Component 一.总结 1.amaze ui:amaze ui是一个web 组件, 由模板(hbs).样式(LESS).交互(JS ...
- AJax 学习笔记二(onreadystatechange的作用)
AJax 学习笔记二(onreadystatechange的作用) 当发送一个请求后,客户端无法确定什么时候会完成这个请求,所以需要用事件机制来捕获请求的状态XMLHttpRequest对象提供了on ...
- nginx 学习笔记(2) nginx新手入门
这篇手册简单介绍了nginx,并提供了一些可以操作的简单的工作.前提是nginx已经被安装到你的服务器上.如果没有安装,请阅读上篇:nginx 学习笔记(1) nginx安装.这篇手册主要内容:1. ...
随机推荐
- Trouble shooting(问题解决):centos 7 gnome show someting has gone wrong.
centos 7 升级 内核 3.10,startx启动不了了.进界面也是oh,no!someting has gone wrong . 参见帖子:http://bbs.csdn.net/topics ...
- Win10 1803 升级之后无法使用 共享目录的解决方法
1. 自己的虚拟机升级了win10 最新版本 1803 但是发现 使用共享文件夹时报错: 2, 百度发现解决方案还是非常简单的. 需要安装一个 功能 3.方法: 开始 运行 输入 control 打开 ...
- KNN python实践
本文实现了一个KNN算法,准备用作词频统计改进版本之中,这篇博文是从我另一个刚开的博客中copy过来的. KNN算法是一个简单的分类算法,它的动机特别简单:与一个样本点距离近的其他样本点绝大部分属于什 ...
- ItemsControl的两种数据绑定方式
最近在学习ItemsControl这个控件的时候,查看了MSDN上面的一个例子,并且自己做了一些修改,这里主要使用了两种方式来进行相应的数据绑定,一种是使用DataContext,另外一种是直接将一个 ...
- xhtml 意義
xhtml是html和xml的結合體. xhtml包含所有xml和html4.0結合的部分. xml是描述語言,html是顯示語言.二者結合可以產生形式良好的文檔. 不僅可以適用與電腦瀏覽器,也可以適 ...
- Omni(USDT)钱包安装(ubuntu)
一.下载Omni Layer钱包 wget https://bintray.com/artifact/download/omni/OmniBinaries/omnicore-0.3.0-x86_64- ...
- 洛谷P4088 [USACO18FEB]Slingshot
题面 大意:给出n个弹弓,可以用ti的时间把xi位置运到yi,在给出m组询问,求xj到yj最小时间. sol:首先如果不用弹弓,时间应为abs(xj-yj).否则时间就是abs(xi-xj)+abs( ...
- BZOJ1041 HAOI2008圆上的整点(数论)
求x2+y2=r2的整数解个数,显然要化化式子.考虑求正整数解. y2=r2-x2→y2=(r-x)(r+x)→(r-x)(r+x)为完全平方数→(r-x)(r+x)/d2为完全平方数,d=gcd(r ...
- idea使用docker-maven-plugin插件将项目编译为docker镜像到远程linux服务器 原
在使用idea开发时,直接docker-maven-plugin插件,把项目编译成docker镜像,然后通过docker:push推送到linux服务器,非常简单,快捷,也避免了手动打包,然后拷贝wa ...
- adb 命令 链接 安装应用
adb connect 192.168.11.1:5555(可省略) adb kill-server 杀掉服务 adb install xxx.apk