初次使用nginx 搭建http2.0

源码的下载地址 html

http://nginx.org/ nginx

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

编译参数 centos

 ./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的时候。 spa

推荐使用这个版本 .net

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

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

nginx伪证书配置 htm

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

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究竟是什么可自行百度了解更多~

相关文章
相关标签/搜索