apache - 如何使用 ubuntu 20.04 在 apache2 上启用 http/2?

标签 apache http ubuntu virtualhost lets-encrypt

我有运行 ubuntu 20.04 (apache2) 的 VPS 服务器,并且正在使用 http/1.1,我想升级到 http/2
该域已经使用 v-hosts 进行了配置(并且安装了 ssl - 让我们加密)。
测试当前协议(protocol):

$ curl -I https://my-domain.com
HTTP/1.1 200 OK
Date: Fri, 12 Mar 2021 17:32:01 GMT
Server: Apache/2.4.41 (Ubuntu)
Content-Type: text/html; charset=UTF-8
我升级到 http/2 的步骤:
1) sudo a2enmod http2

2) add in virtual host (ex: /etc/apache2/sites-enabled/my-domain.com-le-ssl.conf) the line:
Protocols h2 http/1.1     

3) check the config
sudo apache2ctl configtest

4) Restart the web server
sudo systemctl reload apache2
再次测试协议(protocol):
$ curl -I https://my-domain.com
HTTP/1.1 200 OK
Date: Fri, 12 Mar 2021 17:57:07 GMT
Server: Apache/2.4.41 (Ubuntu)
Upgrade: h2
Connection: Upgrade
Content-Type: text/html; charset=UTF-8
如您所见,它仍在使用 http/1.1
我还从 2.4.41 -> 2.4.46 更新了 apache2 ...但同样的问题。
我错过了什么 ???
** 更新 **
apache2 加载的模块
 $ sudo apachectl -M
 Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 filter_module (shared)
 headers_module (shared)
 http2_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php7_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)
已安装 php 7.4.3
php 
libapache2-mod-php 
php-mysql 
php-cli 
php-mbstring 
php-imagick 
php-xml 
php-gd 
php-zip 
php-curl 
php-opcache 
php-soap 
php-bcmath
虚拟主机配置:
<VirtualHost *:80>
    ServerAdmin admin@my-domain.com
    ServerName my-domain.com
    ServerAlias www.my-domain.com
    DocumentRoot /var/www/my-domain.com/public

    Protocols h2 http/1.1 

    <Directory /var/www/my-domain.com/public/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =my-domain.com [OR]
RewriteCond %{SERVER_NAME} =www.my-domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
和 ssl 配置:
<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin admin@my-domain.com
    ServerName my-domain.com
    ServerAlias www.my-domain.com
    DocumentRoot /var/www/my-domain.com/public

    Protocols h2 http/1.1 

    <Directory /var/www/my-domain.com/public/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/my-domain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/my-domain.com/privkey.pem
</VirtualHost>
</IfModule>

最佳答案

  • 将 mpm_prefork 替换为 mpm_event
  • 使用 php-fpm (libapache2-mod-fcgid) 而不是 (libapache2-mod-php)

  • 解决问题。

    关于apache - 如何使用 ubuntu 20.04 在 apache2 上启用 http/2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66607781/

    相关文章:

    php - 我的 htaccess 正确吗?

    angular - 在 Tomcat Apache 生产服务器中部署 Angular 7 PWA 应用程序

    apache - 使用 .htaccess 匹配重写规则中的问号

    http - WinHTTP解压功能?

    Docker swarm leave --force - 超过上下文截止日期

    mysql - 无法在 mysql-apt-config [Ubuntu 14.04] 中选择 'OK'

    java - apache http 客户端 org.apache.http.NoHttpResponseException : The target server failed to respond

    http - 我是否应该根据协议(protocol)前缀区分 OpenID? http 与 https

    android - 将自定义 header 数据添加到 Android HTTP 请求

    Git 推送到 GitHub 失败 - 似乎正在尝试使用 HTTP?