How to Enable and Configure HTTP/2 in Apache on CentOS 8
HTTP/2 is a modernized version of the traditional HTTP protocol, designed to improve website speed and reduce the load on both the web server and network bandwidth. These enhancements not only lead to better performance and lower infrastructure costs, but can also positively impact your site's search engine ranking. In this tutorial, we’ll walk through the steps to enable and configure the HTTP/2 protocol on an Apache web server running CentOS 8. To begin, make sure you have a properly configured server with Apache installed and SSL enabled.
SSL certificate installed on Apache. You can use this tutorial how to Setup Let’s Encrypt SSL on Apache. Most browsers only work with HTTP/2 over HTTPS.
In the Serverspace you can create a server with already installed app "Apache".
Preparing the system
First, you need the latest version of Apache. Therefore, you need to update the packages in the system.
On CentOS/RHEL 8 systems mod_http2 is installed with Apache. To make sure that it is in the system, or install it if not:
Apache configuration for HTTP/2
Make sure that the HTTP/2 module is enabled in Apache.
Output:
Open the configuration file for your virtual host and find the section VirtualHost *:443
It may also be in the domain-name.com-le-ssl.conf file. Add the Protocols parameter there.
Protocols h2 http/1.1
...</virtualhost>
Save and close the file, and then restart Apache.
Check if HTTP/2 works
You can check it this way:
Output:
...
Conclusion
Enabling HTTP/2 on your Apache server running CentOS 8 is a straightforward process that brings significant performance benefits. By supporting features like multiplexing and header compression, HTTP/2 reduces latency and improves load times for your website users. Additionally, since most browsers require HTTPS for HTTP/2, configuring an SSL certificate is a crucial step. With just a few commands and configuration edits, your server can take advantage of this modern protocol—enhancing both user experience and SEO potential.
FAQ
- Q: Is HTTP/2 supported without SSL?
A: Technically, HTTP/2 can work without SSL, but major browsers only support HTTP/2 over HTTPS. So an SSL certificate is required for practical use. - Q: How can I tell if HTTP/2 is working?
A: You can run curl -I https://your-domain.com and check if the response includes HTTP/2 200. You can also use browser developer tools or online services like tools.keycdn.com/http2-test. - Q: Do I need to reinstall Apache to use HTTP/2?
A: No, Apache on CentOS 8 comes with the mod_http2 module included. You just need to ensure it’s installed and enabled. - Q: Will enabling HTTP/2 break existing websites?
A: No, HTTP/2 is backward-compatible. Clients that don’t support HTTP/2 will automatically fall back to HTTP/1.1. - Q: Does HTTP/2 require any changes to my website's code?
A: No changes to your website code are required. HTTP/2 works at the protocol level and is handled by the server and browser.