nginx http2配置

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:59:251336Durchsuche

HTTP 2.0即超文本传输协议 2.0,是下一代HTTP协议。是由互联网工程任务组(IETF)的Hypertext Transfer Protocol Bis (httpbis)工作小组进行开发。是自1999年http1.1发布后的首个更新。
HTTP/2 协议是从 SPDY 演变而来,SPDY 已经完成了使命并很快就会退出历史舞台(例如 Chrome 将在「2016 年初结束对 SPDY 的支持」;Nginx、Apache 也已经全面支持 HTTP/2 ,并也不再支持 SPDY)。

一般的大家把 HTTP2 简称为 h2,尽管有些朋友可能不怎么愿意,但是这个简称已经默认化了,特别是体现在浏览器对 HTTP2 都是这个简写的。

一:nginx的安装

http2需要ssl的支持,需要的软件包如下

nginx-1.9.12.tar.gz
openssl-1.0.1s.tar.gz
pcre-8.38.zip
zlib-1.2.8.tar.gz

默认编译的 nginx 并不包含 http2 模块。所以编译nginx的时候,至少需要启用 http_v2_module 和 http_ssl_module 这两个模块

./configure --prefix=/usr/local/nginx --with-zlib=/tmp/2/zlib-1.2.8 --with-pcre=/tmp/2/pcre-8.38 --with-http_v2_module --with-http_ssl_module  --with-openssl=/tmp/2/openssl-1.0.1s

注意,指定的是openssl,pcre,zlib 的源码包路径,不是安装后的路径

然后

make

make install

二:使用openssl创建SSL证书

参照:http://blog.csdn.net/mn960mn/article/details/42374597

三:nginx的配置

server {
        listen       443 ssl http2;
        server_name  http2.yuni.com;

        ssl_certificate      /usr/local/nginx/ssl/server.crt;
        ssl_certificate_key  /usr/local/nginx/ssl/server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers off; 

        location / {
            root   html;
            index  index.html index.htm;
        }
}

保存退出,然后启动nginx

四:测试

最好使用最新版的chrome、firefox浏览器,我这里使用chrome v49

在本地hosts里面配置http2.yuni.com指向nginx的ip地址

然后,访问https://http2.yuni.com  注意,一定要使用https

查看nginx的access.log日志

nginx http2配置

以上就介绍了nginx http2配置,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn