Chrome一直不请求HTTP/2.0

nginx已经正确配置http2 但是chrome访问的时候总是请求HTTP 1.1,
但用safari和firefox访问时是2.0。

stackoverflow传送门
http://stackoverflow.com/questions/37717417/chrome-51-0-2704-84-not-requesting-http-2-0-but-safari-an-firefox-did

nginx版本1.10.0
Chrome版本51.0.2704.84
Safari版本9.1.1
Firefox版本47.0

Chrome已经尝试清除缓存,但无效

配置文件

worker_processes 2;
events {
    worker_connections 1024;
    multi_accept on;
    use epoll;
}

http {
    sendfile on;

    server {
        listen 80;
        location / {
            return 301 https://$host$request_uri;
        }
    }

    server {
        listen 443 ssl http2;

        ssl_certificate     /usr/cer/server.cer;
        ssl_certificate_key /usr/cer/server.key;

        location / {
            root   /usr/share/nginx/html;
            index  index.html;
        }
    }
}

日志信息
上面是Chrome访问,下面是Safari
clipboard.png

使用Firefox

clipboard.png

====================== 朴素的分割线 =========================

相关链接
https://www.nginx.com/blog/supporting-http2-google-chrome-users/
https://imququ.com/post/enable-alpn-asap.html

楼主已经制作好了最新的nginx 1.11.1镜像(包括 openssl 1.0.2h 模块)
docker hub: https://hub.docker.com/r/tommyzzm/nginx/tags/
github: https://github.com/tommyZZM/docker-hub/tree/master/nginx

下载 docker pull tommyzzm/nginx:1.11.1-alpine-3.3

阅读 9.4k
2 个回答

Chrome 51之后,放弃了对NPN的支持。也就是要求服务端支持ALPN,才能正常的协商至HTTP/2协议。需要OpenSSL 1.0.2以上版本才支持ALPN。具体可见这篇文章。为什么我们应该尽快支持 ALPN?
我的个人网站也遇到了这个问题,我的解决方案是升级至Ubuntu 16.04。另外一种解决方案是,将nginx运行在docker容器中。还有一种解决方案是,自行编译openssl和nginx。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进