centos 启用mod_http2并在conf文件中设置协议后,HTTP/2配置未运行[重复]

dtcbnfnu  于 2022-11-07  发布在  其他
关注(0)|答案(1)|浏览(260)

此问题在此处已有答案

Enabling http/2 in Apache 2.4 does not work(1个答案)
三年前就关门了。
HTTP/2似乎没有运行后,似乎是一个正确的安装。
我运行的是CentOS 7。
我安装了Apache的最新版本,版本httpd-2.4.35-5.el7.x86_64,并一直在尝试让HTTP/2工作。
为此,我看到我们需要运行http2_module。它是活动的并且正在运行。我相信已经通过运行命令httpd -M确认了这一点。http2_module(shared)列在这些模块下面。
接下来我知道要做的是在<VirtualHost ...>标签上添加Protocols h2 h2c http/1.1。我也做过。
最后,我已经弯曲了我的URL,我仍然得到HTTP/1.1。
CURL命令: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可以工作。然而,它不是,我也不知道为什么。

vu8f3i0k

vu8f3i0k1#

在浏览了错误日志之后,我终于找到了问题所在。
[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,然后它就工作了。

相关问题