apache - 启用 mod_http2 并在 conf 文件中设置协议后 HTTP/2 配置未运行
问题描述
在似乎正确安装之后,HTTP/2 似乎没有运行。
我正在运行 CentOS 7。
我安装了最新版本的 Apache,版本 httpd-2.4.35-5.el7.x86_64,并且一直在尝试让 HTTP/2 正常工作。
为此,我看到我们需要运行 http2_module。那是活跃的和正在运行的。我相信已经通过运行命令确认了这一点httpd -M
。http2_module(共享)列在这些模块下。
我知道要做的下一件事是在标签Protocols h2 h2c http/1.1
上方添加。<VirtualHost ...>
我也这样做了。
最后,我已经将我的 URL 卷曲了,我仍然得到 HTTP/1.1。
卷曲命令:curl -vsko /dev/null --http2 https://www.thehomepainter.com
CURL 的简短回应:
GET / HTTP/1.1 主机:www.thehomepainter.com 用户代理:curl/7.64.0 接受:/
< HTTP/1.1 200 正常
部分来自 httpd.conf
Protocols h2 h2c http/1.1
<VirtualHost *:443>
SSLEngine on
ServerAdmin ### omitted ###
ServerName thehomepainter.com
ServerAlias www.thehomepainter.com
DocumentRoot /var/www/html/
Options -Indexes
ProxyRequests off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
ProxyPass "/" "http://localhost:3000/"
ProxyPassReverse "/" "http://localhost:3000/"
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile ### omitted ###
SSLCertificateKeyFile ### omitted ###
SSLCertificateChainFile ### omitted ###
# i have tried this here as well
# Protocols h2 h2c http/1.1
</VirtualHost>
Protocols h2 h2c http/1.1
<VirtualHost *:80>
ServerAdmin support@thedesignguis.com
ServerName thehomepainter.com
ServerAlias www.thehomepainter.com
DocumentRoot /var/www/html
RewriteEngine on
RewriteCond %{SERVER_NAME} =thehomepainter.com [OR]
RewriteCond %{SERVER_NAME} =www.thehomepainter.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
# i have tried this here as well
# Protocols h2 h2c http/1.1
</VirtualHost>
所以预期的结果是 HTTP/2 可以工作。然而,事实并非如此,我也不知道为什么。
解决方案
在翻阅错误日志后,我终于找到了问题所在。
[http2:warn] [pid 7155] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
为了解决,我编辑了 /etc/httpd/conf.modules.d/00-mpm.conf
注释掉这一行:
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
并取消注释底线:
LoadModule mpm_event_module modules/mod_mpm_event.so
重新启动apache,然后它就可以工作了。
推荐阅读
- node.js - 对多个基本 node.js 请求感到困惑
- javascript - 为什么此事件侦听器会在添加之前接收已发送的事件
- c# - 无法在 winform 的事件处理程序中传递空参数?
- opencv - 如何将 OpenCL gpu 内存映射到 OpenCV 矩阵?
- javascript - 分配给 onreadystatechange 的方法怎么执行得这么快?
- python - 如何在 Tornado 中使用 OpenID 进行身份验证?
- typescript - 打字稿:文字类型的用户定义类型保护?
- r - 如何从 R 并行运行相同的 NetLogo 模拟?
- c# - 将布尔值绑定到按钮可见性
- c# - 我们如何在 ASP.Net Core 中使用 HttpClient?