我创建了一个 DigitalOcean droplet,预设了“LAMP 18.04”,并进行了所有更新。配置了一个新的虚拟主机,并使用 certbot 配置了 HTTPS。到目前为止,一切正常。然后我尝试启用 HTTP2:
a2enmod http2
- 已添加
Protocols h2 http/1.1
到 HTTPS 虚拟主机
但是,浏览器在连接到网站时仍使用 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
此外,https://tools.keycdn.com/http2-test显示以下内容:
我的问题是 - 为什么选择 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>