一、获取安装包

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的配置过程的更多相关文章

  1. Nginx 支持websocket的配置

    Nginx 支持websocket的配置server { listen 80; server_name 域名; location / { proxy_pass http://127.0.0.1:808 ...

  2. nginx支持http2协议

    1.http2协议 HTTP 2.0 的主要目标是改进传输性能,实现低延迟和高吞吐量.从另一方面看,HTTP 的高层协议语义并不会因为这次版本升级而受影响.所有HTTP 首部.值,以及它们的使用场景都 ...

  3. Nginx支持多站点配置小结

    如何配置 web 服务器才能在一个 VPS 上放置多个网站/博客呢?如何通过一个 IP 访问多个站点/域名呢?这是大多数 web 服务器支持的 virtual hosting 功能.即一个IP对应多个 ...

  4. php nginx 负载均衡简单配置过程

    负载均衡 负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 简单了解一下什么是负载均衡,单从字面上的意思来理解就可以解 ...

  5. windows下搭建nginx+php+虚拟主机配置过程

    需要软件信息: nginx php RunHiddenConsole 首先安装之前要规划一下把他们放到那里,比如我将他们统一放在e :/web下 那么将这些都拷贝过来,开始吧,window要执行php ...

  6. Nginx和FastDfs完整配置过程

    借鉴(https://blog.csdn.net/qq_34301871/article/details/80060235) 1.unknown directive "ngx_fastdfs ...

  7. nginx配置支持http2

    1.简介 nginx 配置支持http2.目前大多数网站都是http1.1(如果你没有特别配置过的话) 一切都是为了访问更快. 2.如何查看自己网站的http版本 最简单的方法就F12啊,我这里是火狐 ...

  8. Ubuntu 16.04 安装配置支持http2的nginx

    第一步 安装最新版本的nginx 对于ubuntu16.04而言 直接装就是最新的 ``` sudo apt-get update sudo apt-get install nginx 查看Nginx ...

  9. 两年来的core折腾之路几点总结,附上nginx启用http2拿来即用的配置

    序:一年多没更新博客园的内容了,core已经发生了翻天覆地的变化,想起2014年这时候,我就开始了从当时还叫k的那套preview都不如的vnext搭建这套系统,陆陆续续它每一次升级,我也相应地折腾, ...

随机推荐

  1. js之鼠标随动后面跟随事件(类似于长龙跟着跑)

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  2. 理解 Redis(1) - Redis 简介

    Redis 的含义 全称: REmote DIctionary Server 远程词典服务器 由于支持 string, list, set, ordered set, hash 等多重数据结构, 因此 ...

  3. 转一个集成速锐的ss 回头试试 补充加速一、Vultr安装锐速

    https://liyuans.com/archives/ssr-serverspeeder-onekey.html Debian/Ubuntu 系统 ShadowsocksR 一键安装脚本 (集成锐 ...

  4. jsp导入数据库数据写法(模板)

    1.导入表格模板 <%@ page language="java" contentType="text/html; charset=utf-8" page ...

  5. Integer的最大值

    来自:https://blog.csdn.net/qq_33611068/article/details/77369050 有这样一道题: 编程测试,遍历 0 到 int所能表示最大的正数,将消耗的时 ...

  6. 优雅地记录Python程序日志2:模块组件化日志记录器

    本文摘自:https://zhuanlan.zhihu.com/p/32043593 本篇将会涉及: logging的各个模块化组件 构建一个组件化的日志器 logging的模块组件化 在上一篇文章中 ...

  7. Memcached遇到的问题及解决办法

    1. memcached make: *** No targets specified and no makefile found. Stop. 其实是因为在安装libevent时增加了版本号导致的, ...

  8. boke练习: springboot整合springSecurity出现的问题,传递csrf

    boke练习: springboot整合springSecurity出现的问题,传递csrf freemarker模板 在html页面中加入: <input name="_csrf&q ...

  9. gradle ----> 安装和使用

    1.安装gradle 参考官网教程:https://gradle.org/install/ 安装的前提:要求安装jdk1.7或者以上 比较重要的一步:配置环境变量,把gradle的bin目录的全路径配 ...

  10. English trip V1 - B 5.Is It Cold Outside? 外面很冷? Teacher:Corrine Key: weather

    In this lesson you will learn to talk about the weather. 本节课将学习到关于天气 课上内容(Lesson) 词汇(Key Word ) # 关于 ...