【问题标题】:enable http2 with apache2 on debian 8在 debian 8 上使用 apache2 启用 http2
【发布时间】:2019-03-24 01:58:13
【问题描述】:

事情是这样的 我启用了 mod_http2 ( apachectl -M 显示:http2_module ) 并将其设置在此虚拟主机中

<VirtualHost *:443>
  ServerName s74.fr
  Protocols h2 h2c http/1.1
  H2Direct on
  H2EarlyHints on

当我运行这个 curl 命令时:我看到 ALPN 在顶部提供 h2

但是在使用浏览器或简单的网站验证器时,根本不会使用 HTTP2 ..

你们对这个话题有什么线索吗?

任何评论、笔记、线索、启发将不胜感激;)

curl -v --http2 https://s74.fr

* Connected to s74.fr (91.121.146.195) 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: C:\prog\ca-bundle.crt
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data] ...

* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ***ALPN, server accepted to use http/1.1***
* Server certificate:
*  subject: CN=s74.fr
*  start date: Oct 10 08:02:34 2018 GMT
*  expire date: Jan  8 08:02:34 2019 GMT
*  subjectAltName: host "s74.fr" matched cert's "s74.fr"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
} [5 bytes data]
> GET / HTTP/1.1
> Host: s74.fr
> User-Agent: curl/7.53.1
> Accept: */*
>
{ [5 bytes data]
< HTTP/1.1 200 OK
< Date: Fri, 19 Oct 2018 06:32:01 GMT
< Server: Apache/2.4.34 (Debian)
< Upgrade: h2,h2c
< Connection: Upgrade
< Etag: 1539924168
< Last-Modified: Fri, 19 Oct 2018 04:42:48 GMT
< Cache-Control: private
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8

【问题讨论】:

  • 好吧,问题出在 mpm_prefork 我已经安装了 php7.2-fpm 和 mpm_worker,并且 http2 alpn 出现了(以及返回正确 304 响应所需的标头):) 这使得我的一天;)
  • 欢迎,发布您的答案而不是在问题中说已解决是很糟糕的。
  • 或者接受别人的回答是他们为你解决了问题,或者至少把你推向了正确的方向......
  • 这样可以吗?,mpm_prefork 和 mod_http2 不友好地绑定在一起..

标签: debian apache2 http2 apache2.4 debian-jessie


【解决方案1】:

感谢 Barry Pollard 的评论 - 在工人 MPM 的事情上,我意识到我的服务器正在运行 MPM_prefork,后来谷歌搜索我意识到我的设置不完整..所以我已经安装并配置了 php7.2 -fpm,禁用 modphp,禁用 mpm_prefork,然后启用 mpm_worker 并立即工作 + 以某种方式支持在 https 模式下获取正确的标头以触发 304 响应

【讨论】:

    【解决方案2】:

    如果您使用的是 mod_prefork,那么 Apache 将在重启时的日志中显示错误。

    您能否将以下内容添加到您的主 apache 配置文件中:

    <IfModule http2_module>
        #Enable HTTP/2 support
        Protocols h2 http/1.1
        LogLevel http2:info
    </IfModule>
    

    然后重新启动。然后提供检查错误日志的开头,看看它是否说明了什么。

    还值得运行httpd -V(或apachectl -V)来查看环境的配置。

    【讨论】:

    • 对不起,但“启用 HTTP/2 支持”给出了无效的命令“启用”,反正我的 http2.conf 文件已经准备好服务器版本:Apache/2.4.34 (Debian) 服务器构建时间:2018-07 -27T19:37:37
    • 很抱歉应该被注释掉。我更感兴趣的是添加 LogLevel,然后在重启后查看错误日志中的输出。
    【解决方案3】:

    取自https://http2.pro/doc/Apache

    Ubuntu / 德班 分布在 Ubuntu 和 Debian 的默认软件存储库中的 Apache Web 服务器不包括启用 HTTP/2 功能所需的 mod_http2。您需要添加包含 mod_http2 的最新 Apache 版本的第三方包源。

    apt-get install software-properties-common python-software-properties
    add-apt-repository ppa:ondrej/apache2
    apt-get update
    

    这将安装一些实用程序(如果尚未安装),帮助我们添加外部 PPA。其次,我们添加了包含最新 Apache2 构建的 ondrej/apache2 PPA。第三,我们会更新您的系统包信息。

    apt-get install apache2
    apachectl -v
    

    这是为了将您现有的 Apache2 版本升级到最新版本。升级后,apachectl -v 命令将显示升级后的 Apache 版本。这将是 2.4.29 或更高版本。

    添加 HTTP/2 支持

    我们强烈建议您首先为您的网站启用 HTTPS 支持。大多数网络浏览器根本不支持纯文本的 HTTP/2。此外,没有任何借口不再使用 HTTPS。 HTTP/2 可以逐个站点启用。找到您网站的 Apache 虚拟主机配置文件,并在开始标记后添加以下内容: 协议 h2 http/1.1

    总体而言,您的配置文件应如下所示:

    <VirtualHost *:443>
      Protocols h2 http/1.1
      ServerAdmin you@your-awesome-site.com
      ServerName your-awesome-site.com
      ...
    </VirtualHost>
    

    更改后,不要忘记重新加载/重启 Apache。

    apachectl restart
    

    另外,下次有机会,我建议您更新到 debian 9。

    【讨论】:

    • 但是如果 mod_http2 没有启用,那么包含的 OP 中的 H2DirectH2EarlyHints 配置应该显示为无法识别的指令错误?
    • 应该的。您还可以使用“chrome://net-internals/#http2”,而您要在单独的选项卡中打开要检查的站点。如果 http2 正常工作,该网站将在此处列出。
    • 同意,但 Curl 输出清楚地显示它被要求但未被使用。但是升级标题在那里。所以 mod_http2 开启了。所以它成功了一半。我怀疑这是工人 MPM 的事情。
    猜你喜欢
    • 2016-05-08
    • 2019-02-18
    • 2017-11-03
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多