How to Enable HTTP/2 protocol support in Apache?
Last Updated :
25 Jun, 2024
HTTP/2 is a significant update to the HTTP protocol. It was created to outperform HTTP 1.1 in terms of performance and latency. The applications operate way faster and more efficiently if we enable HTTP/2 on our Apache server.
Prerequisites
- Apache Version: 2.4.17 or later.
- OpenSSL Version: Ensure OpenSSL version 1.0.2 or later is installed, as ALPN (Application-Layer Protocol Negotiation) support is required for HTTP/2.
- SSL/TLS: HTTP/2 requires an SSL/TLS connection, so your Apache server must be configured to use HTTPS.
Step to Enable HTTP/2 in Apache
Step 1: Update Apache
Check, your Apache installation is up to date. On Ubuntu or Debian-based systems, you can update Apache using:
sudo apt update
sudo apt upgrade
Step 2: Enabling SSL Module
Enable SSL Module using the following command
sudo a2enmod ssl
Step 3: Enable HTTP/2 Module
Enable the HTTP/2 module in Apache. On Ubuntu/Debian systems.
sudo a2enmod http2
Step 4: Configure Apache to Use HTTP/2
Now, Edit your Apache SSL configuration file.
location:
/etc/apache2/sites-available/default-ssl.conf (Ubuntu/Debian)
/etc/httpd/conf.d/ssl.conf.( windows)
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key
Protocols h2 http/1.1
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Ensure Protocols h2 http/1.1 is added within the VirtualHost block.
Step 5: Restart Apache
After making these changes, restart Apache to apply the new configuration:
sudo systemctl restart apache2
Step 6: Verify HTTP/2 is Enabled
You can verify that HTTP/2 is enabled using a web browser or an online HTTP/2 checker. For a command-line approach
command:
curl -I -k -s --http2 https://www.example.com
Look for HTTP/2 200 or similar in the output, indicating HTTP/2 support.
Troubleshooting
- Check Apache Logs: If Apache fails to restart or HTTP/2 is not enabled, check the Apache error logs.
location
/var/log/apache2/error.log (Ubuntu/Debian).
- Ensure ALPN Support: Verify that your OpenSSL version supports ALPN. You can check your OpenSSL version with openssl version.
openssl version
- Configuration Errors: Ensure there are no syntax errors in your Apache configuration files by running:
sudo apachectl configtest
Conclusion
If we enable HTTP/2 on Apache server it enhances the performance of application by improving the page time loades. By following this guide steps oulined you can easily enable HTTP/2 in your apache server.
Similar Reads
How to Change Apache HTTP Port in Linux? The Apache HTTP server is one of the internet's most popular web servers today, thanks to its versatility, consistency, and a plethora of features, some of which are actually not available on other web servers, such as Nginx's competitor. Some of Apache's most significant features include the abilit
2 min read
How to Disable HTTP Methods in Apache? To prevent the collection of specific system calls that could offer attackers Windows running Apache servers a backdoor, we can Turn off unwanted HTTP methods on the Apache web server. This increases the security of our web application and prevents unwanted attacks. PrerequisitesApache InstalledAdmi
2 min read
How to Enable HTTP/2 in Apache 2.4 on Ubuntu 20.04? Apache 2.4 with HTTP/2 enabled on Ubuntu 20.04 will greatly enhance your web server's performance. Compared to HTTP/1.1, HTTP/2 has several benefits, such as server push, header compression, and multiplexing.PrerequisitesUbuntu 20.04Apache 2.4.17 or later (HTTP/2 functionality is available beginning
3 min read
How To Enable mod_ssl in Apache? The mod_ssl module in Apache allows you to secure the web server with SSL or TLS encryption. This article will show how to enable mod_ssl in apache to ensure the your website handles secure HTTPS connections. PrerequisitesApache HTTP Server.Administrative privileges on the Windows system.A valid SSL
3 min read
How to Enable HTTP Strict Transport Security (HSTS) for Apache? HTTP Strict Transport Security (HSTS) is a security policy component that assists with safeguarding sites against protocol for downsize attacks and cookies highjacking by forcing the HTTPS connections. Using HSTS on your Apache web server improves the security of your site.PrerequisitesAccess: Admin
5 min read