简体   繁体   English

在Debian 8上使用apache2启用http2

[英]enable http2 with apache2 on debian 8

here's the thing I've enabled mod_http2 ( apachectl -M shows : http2_module ) and set this within this vhost 这是我启用了mod_http2(apachectl -M显示为:http2_module)并在此虚拟​​主机中设置的东西

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

Thing is when I run this curl command : I see ALPN offering h2 at the top 是当我运行以下curl命令时:我看到ALPN在顶部提供h2

But while using a browset or simple website validator, HTTP2 is never used at all .. 但是,在使用浏览器或简单的网站验证器时,根本不会使用HTTP2。

Do you guys have any clue on this topic ? 你们对这个话题有什么线索吗?

Any remarks, notes, clue, enlightment would be greatly appreciated ;) 任何评论,注释,线索,启示将不胜感激;)

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

If you are using mod_prefork then Apache will show an error in the logs on restart. 如果您使用的是mod_prefork,则Apache在重启时将在日志中显示错误。

Can you add the following to your main apache config file: 您可以将以下内容添加到主apache配置文件中吗:

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

Then restart. 然后重新启动。 Then provide check the start of the error log to see if it says anything. 然后提供检查错误日志的开始以查看是否显示任何内容。

It would also be worth running httpd -V (or apachectl -V ) to see what the environment is configured for. 运行httpd -V (或apachectl -V )来查看环境的配置也是值得的。

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

Ubuntu / Debain Apache web server distributed in default software repositories of Ubuntu and Debian do not include mod_http2 needed to enable HTTP/2 functionality. Ubuntu / Debain在Ubuntu和Debian的默认软件存储库中分发的Apache Web服务器不包含启用HTTP / 2功能所需的mod_http2。 You will need to add a third-party package source with latest Apache version that also inludes mod_http2. 您将需要添加具有最新Apache版本的第三方程序包源,其中也包括mod_http2。

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

This will install some utilities (if not installed already) that help us add external PPAs. 这将安装一些实用程序(如果尚未安装),可帮助我们添加外部PPA。 Secondly, we add the ondrej/apache2 PPA which contains the latest Apache2 builds. 其次,我们添加了ondrej / apache2 PPA,其中包含最新的Apache2构建。 Third, we update your systems package information. 第三,我们更新您的系统软件包信息。

apt-get install apache2
apachectl -v

This is to upgrade your existing Apache2 version to the latest version. 这是将现有的Apache2版本升级到最新版本。 After upgrading, the apachectl -v command will reveal your upgraded Apache version. 升级后,apachectl -v命令将显示您升级的Apache版本。 This will be 2.4.29 or later. 这将是2.4.29或更高版本。

Add HTTP/2 Support 添加HTTP / 2支持

We highly recommend you enable HTTPS support for your web site first. 强烈建议您首先为网站启用HTTPS支持。 Most web browser simply do not support HTTP/2 over plain text. 大多数Web浏览器根本不支持纯文本格式的HTTP / 2。 Besides, there are no excuses to not use HTTPS anymore. 此外,没有任何理由不再使用HTTPS。 HTTP/2 can be enabled site-by-site basis. 可以逐站点启用HTTP / 2。 Locate your web site's Apache virtual host configuration file, and add the following right after the opening tag: Protocols h2 http/1.1 找到您网站的Apache虚拟主机配置文件,并在开始标记后添加以下内容:Protocols h2 http / 1.1

Overall, your configuration file should look something like this: 总体而言,您的配置文件应如下所示:

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

After the changes, don't forget to reload/restart Apache. 更改之后,不要忘记重新加载/重新启动Apache。

apachectl restart

Also, next chance you can get, I'd recommend updating to debian 9. 另外,如果有机会,我建议您升级到Debian 9。

多亏了Barry Pollard的评论-在工作人员MPM方面,我已经意识到我的服务器正在运行MPM_prefork,在后来的谷歌搜索中,我已经意识到我的设置尚未完成..因此,我安装并配置了php7.2-fpm禁用了modphp,禁用了mpm_prefork,然后启用了mpm_worker,它立即工作,并且以某种方式提供了对在https模式下获取正确标题以触发304响应的支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM