1

I have VPS server running ubuntu 20.04 (apache2) and is using http/1.1 and I want to upgrade to http/2

The domain is already configured using v-hosts (and has the ssl installed - lets encrypt).

Testing the current 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

Steps that I done to upgrade to 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

Test again the ptotocol:

$ 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

As you can see it still using the http/1.1

I also updated the apache2 from 2.4.41 -> 2.4.46 ... but the same problem.

What did I miss ???

** UPDATE **

apache2 loaded modules

 $ 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 installed

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

vhost config:

<VirtualHost *:80>
    ServerAdmin [email protected]
    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>

and the ssl config:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin [email protected]
    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>

2 Answers 2

1
  1. Replacing the mpm_prefork with mpm_event
  2. using php-fpm (libapache2-mod-fcgid) instead of (libapache2-mod-php)

solve the problems.

0

You should probably add the --http2 option to your curl command

5
  • the same thing. I have updated the post with the apache config ...
    – calin24
    Commented Mar 13, 2021 at 12:10
  • Can you try adding h2c to the protocols ?
    – Faeeria
    Commented Mar 13, 2021 at 12:11
  • h2c is for clear text. It should work with h2 .... if I am not sure what I miss....
    – calin24
    Commented Mar 13, 2021 at 12:27
  • You do have the prefork module enabled, which causes problems with HTTP2
    – Faeeria
    Commented Mar 13, 2021 at 12:29
  • If I am correct the mpm_prefork will work only with php-fpm, right ? I am using php-cli ... I remember that I had php-fpm and had some problems with my laravel apps .. then i replaced the fpm with cli.
    – calin24
    Commented Mar 13, 2021 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.