ALPN 协商选择 http/1.1 而不是 h2

Xym*_*nek 4 https apache-2.4 alpn

我创建了一个带有“LAMP 18.04”预设的 DigitalOcean Droplet 并进行了所有更新。配置新的虚拟主机并使用 certbot 配置 HTTPS。到目前为止一切都工作正常。然后我尝试启用 HTTP2:

  • a2enmod http2
  • 添加Protocols h2 http/1.1HTTPS虚拟主机

但是,浏览器在连接到站点时仍然使用 HTTP/1.1(禁用缓存)。运行时curl --http2 -v https://example.com(域混淆)将打印以下内容:

* Connected to example.com (1.1.1.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
...
* SSL connection using TLSv1.2 / ECDHE-RSA-CHACHA20-POLY1305
* ALPN, server accepted to use http/1.1

... And in headers:
< Upgrade: h2
< Connection: Upgrade
Run Code Online (Sandbox Code Playgroud)

此外,https://tools.keycdn.com/http2-test显示以下内容:

HTTP2测试工具截图

我的问题是 - 为什么选择 http/1.1?另外,为什么该工具认为 HTTP2/ALPN 已禁用?这是完整的 VHost 配置:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName example.com
        DocumentRoot /var/www/example/www
        Protocols h2 http/1.1

        ErrorLog ${APACHE_LOG_DIR}/example/error.log
        CustomLog ${APACHE_LOG_DIR}/example/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

        <FilesMatch "^index\.html$">
            Include no-cache.conf
        </FilesMatch>

Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias www.example.com
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>
Run Code Online (Sandbox Code Playgroud)

HBr*_*ijn 5

大多数发行版仍然默认使用 prefork MPM。(除非您确实必须将 mod_php 与非常蹩脚的古代代码一起使用,否则在当今时代没有理由再这样做。)

Apache 中的 HTTP/2 支持与 prefork MPM 相结合有很多限制,实际上它不会带来 HTTP/2 的任何好处。这可能就是为什么测试标头表明 HTTP/2 和ALPN, offering h2支持,但进一步测试显示失败。

切换到不同的 MPM,您应该可以让 HTTP/2 真正工作。