upgrade - Ubuntu 18.04 中的 HTTP/2

标签 upgrade h2 http2 alpn

我想在此网站上尝试 HTTP/2:https://www.alebalweb-blog.com/

我最近使用 PHP 7.2、Apache/2.4.29 等将服务器更新到 Ubuntu 18.04

我做了:sudo a2enmod http2

添加:

#HTTP/2
Protocols h2 h2c http/1.1

在我的 VirtualHost SSL 中。

并重新启动 Apache。

SSL 证书由 Let's Encrypt 提供。

结果是:

curl -k -v --http2 https://alebalweb-blog.com
* Rebuilt URL to: https://alebalweb-blog.com/
*   Trying 45.76.70.142...
* TCP_NODELAY set
* Connected to alebalweb-blog.com (45.76.70.142) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-CHACHA20-POLY1305
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=alebalweb-blog.com
*  start date: Jul  7 02:02:06 2018 GMT
*  expire date: Oct  5 02:02:06 2018 GMT
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
> GET / HTTP/1.1
> Host: alebalweb-blog.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 13 Jul 2018 21:51:22 GMT
< Server: Apache/2.4.29 (Ubuntu)
< Upgrade: h2,h2c
< Connection: Upgrade
< Cache-Control: max-age=300
< Expires: Fri, 13 Jul 2018 21:56:22 GMT
< Vary: Accept-Encoding,User-Agent
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8

我认为真的很奇怪:

Upgrade: h2,h2c
Connection: Upgrade

这是什么意思?

HTTP/2 测试说:

HTTP/2 Test Result www.alebalweb-blog.com
Negative! www.alebalweb-blog.com does not support HTTP/2.0.
ALPN is not supported.

我觉得我错过了一些大事......你能帮我理解什么吗?

最佳答案

我想我通过切换到 PHP-FPM 解决了

我使用了这些代码:

apachectl stop
apt-get install php7.1-fpm # Install the php-fpm from your PHP repository. This package name depends on the vendor.
a2enmod proxy_fcgi setenvif
a2enconf php7.1-fpm # Again, this depends on your PHP vendor.
a2dismod php7.1 # This disables mod_php.
a2dismod mpm_prefork # This disables the prefork MPM. Only one MPM can run at a time.
a2enmod mpm_event # Enable event MPM. You could also enable mpm_worker.
apachectl start

来自本指南:https://http2.pro/doc/Apache 和本指南:https://techwombat.com/enable-http2-apache-ubuntu-16-04/

并在/etc/apache2/apache2.conf 末尾添加“Protocols h2 h2c http/1.1”

现在命令curl -k -v --http2 https://alebalweb-blog.com报告如下:

curl -k -v --http2 https://alebalweb-blog.com
* Rebuilt URL to: https://alebalweb-blog.com/
*   Trying 45.76.70.142...
* TCP_NODELAY set
* Connected to alebalweb-blog.com (45.76.70.142) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=alebalweb-blog.com
*  start date: Jul  7 02:02:06 2018 GMT
*  expire date: Oct  5 02:02:06 2018 GMT
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x556ec5957940)
> GET / HTTP/2
> Host: alebalweb-blog.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200 
< date: Thu, 19 Jul 2018 20:21:38 GMT
< server: Apache/2.4.34 (Ubuntu)
< cache-control: max-age=300
< expires: Thu, 19 Jul 2018 20:26:38 GMT
< vary: Accept-Encoding,User-Agent
< content-type: text/html; charset=UTF-8

首先您会注意到此更改:ALPN、服务器接受使用 h2 和 HTTP/2 200

网站https://tools.keycdn.com/http2-test ,说:

Yeah! www.alebalweb-blog.com supports HTTP/2.0. 
ALPN supported.

且opera和chrome的开发工具均显示:h2

我只有最后一个疑问,在 Google 网站管理员工具中,以 Google 身份获取页面,我看到了这一点:

HTTP/1.1 200 OK
Date: Thu, 19 Jul 2018 20:35:35 GMT
Server: Apache/2.4.34 (Ubuntu)
Upgrade: h2,h2c
Connection: Upgrade, Keep-Alive
Cache-Control: max-age=300
Expires: Thu, 19 Jul 2018 20:40:35 GMT
Vary: Accept-Encoding,User-Agent
Content-Type: text/html; charset=UTF-8
Content-Length: 41422
Keep-Alive: timeout=5, max=100

我错过了什么吗?或者也许需要时间?

关于upgrade - Ubuntu 18.04 中的 HTTP/2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51333383/

相关文章:

java - 如何使用 H2 的 CSVREAD() 函数/查询在 WAR 中访问 CSV 文件?

java - 如何在java中从H2数据库映射id列

javascript - 实验警告 : The http2 module is an experimental API

sql-server - 将 SQL Server 2000 升级到 2005 或 2008 - DTS 到 SSIS

magento - 从Magento 2.0.2升级失败 "An error has happened during application run. See exception log for details."

mysql - Magento如何管理外键约束

server-sent-events - 服务器发送的事件是否使用 HTTP/2 管道

magento - Composer 2,你的一些插件似乎与它不兼容

java - H2 数据库 URL 错误

Jetty HTTP2 服务器推送支持