Configuring http / 2.0 with nginx in Windows

Time:2021-3-3

Http2 has been released for a long time. Compared with 1.0, http2 has been greatly improved. On the premise of semantic compatibility with 1.0, it greatly improves web performance and further reduces network latency.
Check whether your browser supports http2, and compare the performance gap between 1.0 and 2.0http2.0

Just recently, when we were testing the website, we were told that we should use the http2 protocol. After searching for some information, the configuration was successful. Now let’s share the process

1 nginx version must be after 1.9.5Official explanation of nginx
2 only support the HTTPS protocol website, how to configure HTTPS? See my another blog postConfigure HTTPS

Configure nginx

server {
    listen       443 ssl http2 default_server;
    server_ Name your domain name;

    ssl_ certificate      D:/nginx-1.15.6/ssl/xxxxx- chain.pem Your certificate
    ssl_ certificate_ key  D:/nginx-1.15.6/ssl/xxxxxx- key.pem Your certificate

    ssl_session_timeout 5m;
    charset utf-8;

    location / {
        root  D:/index/;
        index index.html;
    }
}

verification

Open the websiteHttp2.0 verificationVerify that your website supports 2.0 protocol