Why does apache2 module http2 not exist on Ubuntu

2019-04-06 17:49发布

问题:

I'd like to install htt2_module. After a fresh installation of Ubuntu 14.04 following the steps listed in this link, I have tried to enable the http2_module just running

sudo a2enmod http2

but I get: Module http2 does not exist!

the apache version installed is:Apache/2.4.7 ,then as a workaround I tried with this link adding the following repository

sudo add-apt-repository ppa:ondrej/apache2

after refreshing with sudo apt-get update, and running again the command to install/enable the http2 I get the same error. Module http2 does not exist.

回答1:

Actually, http2 module is supported on apache 2.4.17 or higher (for better stability you should use at least 2.4.23) but default apache for Ubuntu 16.04 or 14.04 is lower than minimum required so in order to upgrade your apache follow below steps:

$ sudo add-apt-repository -y ppa:ondrej/apache2

$ sudo apt-key update

$ sudo apt-get update

then run

$ sudo apt-get --only-upgrade install apache2 -y

here you will be promted two times like :

*** apache2.conf (Y/I/N/O/D/Z) [default=N] ?

press Y both the times and proceed.

Check your mods-available folder you will see http2.load file

$ sudo a2enmod http2

you will get following output

Enabling module http2. To activate the new configuration, you need to run: service apache2 restart



回答2:

  1. Upgrade Apache to Latest

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

Apache version should be 2.4.25 or later.

  1. Enable it from mod_http2

    a2enmod http2 
    service apache2 restart
    
  2. Add Self-Signed OR Valid SSL to your website to enable http2 on your server.
    Link:- https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04

  3. Add HTTP/2 Support to Apache2 Virtual Host file. Example :

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

And Restart Apache2 Services

service apache2 restart
  1. Apache2 on HTTP/2 does not support in mpm_prefork mode, change it to mpm_event.PHP version should be php5.6 or greater.

    service apache2 stop 
    apt-get install php7.1-fpm 
    a2enmod proxy_fcgi setenvif 
    a2enconf php7.1-fpm 
    a2dismod php7.1 
    a2dismod mpm_prefork 
    a2enmod mpm_event 
    service apache2 start 
    

Now test your configuration by visiting your server's domain name or public IP address like this: https://server_domain_name_or_IP

To check the HTTP/2 Protocol working or not, Go to Inspect Elements in your Browser and in Network Section you can check http protocol version.