初次使用nginx 搭建http2.0

jopen 8年前

源码的下载地址

http://nginx.org/

目前1.9.5已经加入http2.0的支持,

编译参数

 ./configure --prefix=/usr/local/nginx --with-openssl=/opt/openssl-1.0.2e --with-pcre --with-zlib=/opt/zlib-1.2.8 --with-stream --with-stream_ssl_module --with-http_ssl_module --with-http_v2_module --with-threads 

这里需要自行下载openssl、zlib源码包,其中openssl需要注意,需要1.0.2以上版本需要对tls支持,否则会报错开启http2的时候。

推荐使用这个版本

wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz

wget http://zlib.net/zlib-1.2.8.tar.gz

nginx伪证书配置

创建服务器私钥,命令会让你输入一个口令:

openssl genrsa -des3 -out server.key 1024

创建签名请求的证书(CSR):

openssl req -new -key server.key -out server.csr

在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:

 cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

具体配置参考

http://nginx.org/en/docs/http/ngx_http_v2_module.html

server {      listen 443 ssl http2;        ssl_certificate server.crt;      ssl_certificate_key server.key;  }


这里请求完成之后连接是保持的,直到超时才会关闭连接

具体想了解http2到底是什么可自行百度了解更多~


来自: http://my.oschina.net/leicc/blog/601293