升级到支持的操作系统

升级到支持的操作系统

我正在尝试配置 HTTP/2 支持,但出现了问题

我的服务器是 Google 计算引擎虚拟机,运行 Debian 9.13 (stretch) 服务器版本 Apache/2.4.25,使用 OpenSSL 配置 SSL 证书。运行时openssl version它会报告版本 1.1.1g。运行时 phpinfo();它会报告 OpenSSL/1.0.2u。PHP 版本 7.4.11 并且phpinfo();还报告...

SSL_VERSION_INTERFACE  ->  mod_ssl/2.4.25
SSL_VERSION_LIBRARY  ->  OpenSSL/1.0.2u
SSL_PROTOCOL  ->  TLSv1.2

我按照说明这里“在 Apache 中启用 HTTP/2 模块”和“在 Apache 虚拟主机中启用 HTTP/2”,以及这里。执行此操作后,当我运行命令时,apache2ctl -M | grep http2它会返回信号http2_module (shared),表示已启用 HTTP/2 支持。但它并未投入生产。

以下是我的 apache2 虚拟主机配置文件中使用的行/etc/apache2/sites-available/default-ssl.conf

<VirtualHost _default_:443>
    Protocols h2 h2c http/1.1
    ...

curl -vso http2_debug.log --http2 https://pharealty.com/这是使用命令成功下载页面时的详细连接信息。

*   Trying 35.236.101.224...
* TCP_NODELAY set
* Connected to pharealty.com (35.236.101.224) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [109 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [4036 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=pharealty.com
*  start date: Jul 10 01:53:04 2021 GMT
*  expire date: Oct  8 01:53:03 2021 GMT
*  subjectAltName: host "pharealty.com" matched cert's "pharealty.com"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
} [5 bytes data]
> GET / HTTP/1.1
> Host: pharealty.com
> User-Agent: curl/7.52.1
> Accept: */*
>
{ [5 bytes data]
< HTTP/1.1 200 OK
< Date: Wed, 08 Sep 2021 17:20:21 GMT
< Server: Apache
< Upgrade: h2,h2c
< Connection: Upgrade
< Set-Cookie: PHPSESSID=1mv9jqka4n7c7fb6qmtavfsgue; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< X-Pingback: https://pharealty.com/xmlrpc.php
< Link: <https://pharealty.com/wp-json/>; rel="https://api.w.org/"
< Link: <https://pharealty.com/wp-json/wp/v2/pages/48>; rel="alternate"; type="application/json"
< Link: <https://pharealty.com/>; rel=shortlink
< Set-Cookie: phaLandingPage=%2F; expires=Tue, 08-Mar-2022 17:20:21 GMT; Max-Age=15638400; path=/
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
{ [7 bytes data]
* Curl_http_done: called premature == 0
* Connection #0 to host pharealty.com left intact

一开始它看起来运行正常,但后来又恢复到 HTTP/1.1

据我所知,我的 OpenSSL 版本已经足够新了。尽管我之前提到的这个页面强烈建议使用高于 2.4.25 的 apache 版本,我无法将 apache 更新到 2.4.25 以外的任何版本。

切换后我需要设置新的 SSL 证书吗?是 Apache 版本导致的问题吗?

我已经在几个 http/2 测试网站上测试过该网站,但每次都失败。

答案1

升级到支持的操作系统

您使用的是 Debian Stretch,在我看来,它的主要支持已经 EOL。(生命周期结束)
安全补丁将一直可用,直到2022-06-30

更改 Apache 处理模块

sudo a2dismod mpm_prefork
sudo a2enmod mpm_event

启用 SSL 和 http2 模块

sudo a2enmod ssl  
sudo a2enmod http2  

全局或通过 vhost 启用 http2 支持

添加到Apache2.conf:

Protocols h2 http/1.1

或者编辑虚拟主机并添加 协议 h2 http/1.1

<VirtualHost *:443>
  ServerName example.com
  ServerAlias www.example.com
  DocumentRoot /var/www/public_html/example.com
  SSLEngine on
  SSLCertificateKeyFile /path/to/private.pem
  SSLCertificateFile /path/to/cert.pem
  SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
  Protocols h2 http/1.1 #add this here
</VirtualHost>

提醒重新加载 Apache 服务器。

sudo systemctl restart apache2

要获取所有 php 版本,你可以查看我的 bash 脚本

https://raw.githubusercontent.com/djdomi/php-install/master/run.sh

参考

关于本指南

相关内容