nginx支持HTTP2的配置过程
一、获取安装包
http://zlib.net/zlib-1.2.11.tar.gz
https://www.openssl.org/source/openssl-1.0.2e.tar.gz (openssl的版本必须在1.0.2e及以上)
http://nginx.org/download/nginx-1.10.3.tar.gz (nginx的版本必须在1.9.5以上)
二、解压三个包到相同目录编译nginx
./configure --prefix=/usr/local/nginx --with-openssl=../openssl-1.0.2e --with-pcre --with-zlib=../zlib-1.2. --with-stream --with-stream_ssl_module --with-http_ssl_module --with-http_v2_module --with-threads
make
make install
三、配置运行
配置nginx伪证书、配置文件中开启https即可
步骤1: 到需要放置证书的目录(选在nginx的conf目录下就可以),建立服务器的私钥(此过程需输入密码短语)
openssl genrsa -des3 -out server.key
步骤2: 创建证书签名请求csr
openssl req -new -key server.key -out server.csr
步骤3:对于使用上面私钥启动具有ssl功能的nginx,有必要移除输出的密码
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
步骤4: 使用上面的私钥和CSR对证书进行签名
openssl x509 -req -days -in server.csr -signkey server.key -out server.crt
步骤5:配置nginx
server {
listen ssl http2;
server_name localhost;
ssl_certificate server.crt;
ssl_certificate_key server.key;
}
步骤6:启动nginx并用firefox浏览器访问
(firefox浏览器的版本必须在35以上,并且在"about:config"中开启了"network.http.spdy.enabled.http2draft"选项)
访问后查看报文,协议版本是否为HTTP 2.0和firefox是否插入了自己的头"X-Firefox-Spdy:"
当然如果到这成功的话,事情也就结束了,偏偏我连升了3次fireforx的版本,都在35以上,最后升级到52版本,然并卵,"about:config"中只有"network.http.spdy.enabled.http2"这一项,而且还是开启的。但是访问的时候,查看请求头,依然是HTTP1.1。谷歌也是一样不行。来不及怀疑人生,只能换curl试试。
四、curl模拟HTTP2.0请求
1. 下载源码安装包
nghttp2:https://codeload.github.com/nghttp2/nghttp2/zip/master
curl: https://curl.haxx.se/download/curl-7.53.1.tar.gz
2. 安装http2
yum install install git g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev libjemalloc-dev cython python3-dev python-setuptools
unzip nghttp2-master.zip
cd nghttp2-master
autoreconf -i
automake
autoconf
./configure
make
sudo make install
3. 安装curl
https://curl.haxx.se/download/curl-7.53.1.tar.gz
tar -zxvf curl-7.53..tar.gz
cd curl-7.53.
./configure --with-nghttp2=/usr/local --with-ssl
make
4. 验证
[root@localhost src]# ./curl --version
curl 7.53. (x86_64-pc-linux-gnu) libcurl/7.53. OpenSSL/1.0.1e zlib/1.2. nghttp2/1.22.-DEV
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz HTTP2 UnixSockets HTTPS-proxy
红色字体说明curl已经支持HTTP2和HTTPS,然后到curl的程序目录,执行,查看nginx是否支持http2;
cd src
./curl --http2 -v https://192.168.0.1/a.jpg -k
日志太多,但是中间会有一行"Using HTTP2, server supports multi-use"说明是用了http2的;
在nginx的access.log中也可以看见访问记录为"GET /a.jpg HTTP/2.0" 200 18082 "-" "curl/7.53.1"也可以说明是用的HTTP2.0
最后我用常用的搜狗浏览器访问"https://192.168.0.1/a.jpg"发现使用的也是HTTP2.0,但是搜狗浏览器的F12里面并没显示这个请求头,nginx的日志中可以看见。
五、参考网址
http://wiki.jikexueyuan.com/project/http-2-explained/firefox.html
https://my.oschina.net/leicc/blog/601293?p={{totalPage}}
http://www.linuxidc.com/Linux/2016-01/127588.htm
nginx支持HTTP2的配置过程的更多相关文章
- Nginx 支持websocket的配置
Nginx 支持websocket的配置server { listen 80; server_name 域名; location / { proxy_pass http://127.0.0.1:808 ...
- nginx支持http2协议
1.http2协议 HTTP 2.0 的主要目标是改进传输性能,实现低延迟和高吞吐量.从另一方面看,HTTP 的高层协议语义并不会因为这次版本升级而受影响.所有HTTP 首部.值,以及它们的使用场景都 ...
- Nginx支持多站点配置小结
如何配置 web 服务器才能在一个 VPS 上放置多个网站/博客呢?如何通过一个 IP 访问多个站点/域名呢?这是大多数 web 服务器支持的 virtual hosting 功能.即一个IP对应多个 ...
- php nginx 负载均衡简单配置过程
负载均衡 负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 简单了解一下什么是负载均衡,单从字面上的意思来理解就可以解 ...
- windows下搭建nginx+php+虚拟主机配置过程
需要软件信息: nginx php RunHiddenConsole 首先安装之前要规划一下把他们放到那里,比如我将他们统一放在e :/web下 那么将这些都拷贝过来,开始吧,window要执行php ...
- Nginx和FastDfs完整配置过程
借鉴(https://blog.csdn.net/qq_34301871/article/details/80060235) 1.unknown directive "ngx_fastdfs ...
- nginx配置支持http2
1.简介 nginx 配置支持http2.目前大多数网站都是http1.1(如果你没有特别配置过的话) 一切都是为了访问更快. 2.如何查看自己网站的http版本 最简单的方法就F12啊,我这里是火狐 ...
- Ubuntu 16.04 安装配置支持http2的nginx
第一步 安装最新版本的nginx 对于ubuntu16.04而言 直接装就是最新的 ``` sudo apt-get update sudo apt-get install nginx 查看Nginx ...
- 两年来的core折腾之路几点总结,附上nginx启用http2拿来即用的配置
序:一年多没更新博客园的内容了,core已经发生了翻天覆地的变化,想起2014年这时候,我就开始了从当时还叫k的那套preview都不如的vnext搭建这套系统,陆陆续续它每一次升级,我也相应地折腾, ...
随机推荐
- 判断是否在同一个线程-GetCurrentThreadId()用法
线程 在一个程序中,这些独立运行的程序片断叫作"线程"(Thread),利用它编程的概念就叫作"多线程处理".利用线程,用户可按下一个按钮,然后程序会立即作出响 ...
- 【Ruby】【遇到的问题】
1 Error fetching https://gems.ruby-china.org/: certificate verify failed (https://gems.ruby-china.or ...
- 【Ruby】【基础】
# [Ruby 块]=begin1 块由大量代码构成2 块中代码包含在{}内3 从与其相同名称的函数调用4 可以使用yield语句调用块=enddef test p '在test方法内' yield ...
- C# 使用 protobuf 进行对象序列化与反序列化
protobuf 是 google的一个开源项目,可用于以下两种用途: (1)数据的存储(序列化和反序列化),类似于xml.json等: (2)制作网络通信协议. 源代码下载地址:https://gi ...
- sklearn中的train_test_split (随机划分训练集和测试集)
官方文档:http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html ...
- Excel 常用设置
首行固定 视图->冻结窗口
- $(document).ready和window.onload,细微小区别,ready是jQuery的方法,onload是window的方法
$(document).ready和window.onload的区别 $(document).ready和window.onload都是在都是在页面加载完执行的函数,大多数情况下差别不大,但也是有区别 ...
- Eclipse添加EGIT方法
1. 安装EGIT, 其中一个方法: 2. 新建javaweb项目,测试git的使用. l File > Team > Share Project 选择GIT 如何选择不了,则选择创建c ...
- vue中兄弟组件间通讯
vue2.0中兄弟组件间的通讯是通过eventBus(事件发布订阅)实现的. eventBus.js import Vue from 'vue' const eventBus = new Vue() ...
- python静态方法、类方法
常规: class Dog(object): def __init__(self,name): self.name=name def eat(self): print('%s is eating'%s ...