Bootstrap

Nginx配置HTTP2.0

安装前必读:

  1. Nginx1.10.0以上版本才支持Http2.0
  2. Http2.0只支持Https协议的网站,且openssl版本需要高于1.0.2

一、查看当前Nginx安装了哪些模块(其实目前Nginx版本都是高于1.10的,所以都是支持的)

# nginx -V

可以看到http2.0模块--with-http_v2_module已经存在了 

二、配置nginx.conf

Nginx配置http2很简单,只需要在listen的端口后新增http2标识即可,如下

server
    {
    	listen              443 ssl http2;
        server_name         fogbow.cn;
        
        root  /home/wwwroot/fogbow.cn;
        index index.html index.htm index.php default.html default.htm default.php;    

        ssl_certificate     /usr/local/nginx/cert/2808248_fogbow.cn.pem;
        ssl_certificate_key /usr/local/nginx/cert/2808248_fogbow.cn.key;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;

        include rewrite/none.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log off;
    }

三、检查http2是否生效
打开chrome控制台,在Name一栏右键把Protocol勾选上

HTTP2.0的新特性网上很多这里就不多说了,可以通过一个链接来对比一下HTTP2.0到底比HTTP1.x快了多少

https://http2.akamai.com/demo

;