Filed under Linux
Tagged as NGINX HTTP/2 OpenSSL Use the Source CentOS7 Chrome
HTTP/2 ON CENTOS7 WITH NGINX
You’ve probably heard about the fancy new lightning fast HTTP/2 protocol, right? Fortunately, the latest versions of NGINX support HTTP/2. Unfortunately, most distributions are still stuck on OpenSSL < 1.0.2.
Versions of OpenSSL below 1.0.2 don’t support the new Application-Layer Protocol Negotition standard (ALPN) which means browsers must use Next Protocol Negotiation (NPN) to upgrade the connection to HTTP/2.
BUT WHAT DOES THIS MEAN? WHY DOES IT MATTER?
This matters because Google Chrome will fall back to HTTP/1.1 if ALPN is not supported. Since most Linux distributions don’t officially support a version of OpenSSL that implements ALPN that means something must be done to if we want to implement HTTP/2 properly.
The official NGINX Blog has a great entry about this exact topic which happens to be where I began this journey. They list which distros support ALPN (at the time of the writing) and which don’t. CentOS7 is in the don’t column.
Our options from here are switch to Ubuntu 16.x, use third party OpenSSL packages, or compile NGINX against a version of OpenSSL that implements ALPN. While compiling your own packages is a bit old school and generally frowned upon for security reasons (any update requires a recompile and that can become a chore) this particular case is pretty easy and low maintenance.
We can compile NGINX against a newer version of OpenSSL without updating the version the rest of the system uses. In fact, we don’t even have to compile openssl. However, please, for the love of all that is holy, make sure you keep your nginx up to date. Any security updates for nginx or openssl means you need to repeat this process with the updated versions.
If you decide to go this route please take security seriously, and keep your software up to date. After you’ve gone through this once updating shouldn’t take more than ten minutes. If you get lazy with security you will eventually regret it. If you aren’t comfortable doing this use a distro that can officially support ALPN.
Here we go.
COMPILING NGINX AGAINST OPENSSL 1.1.0C
I chose to use OpenSSL 1.1.0c because it’s the newest version. Make sure to get the most recent version of 1.1.0 or 1.0.2 depending on which version you decide to use. OpenSSL is updated frequently with security updates.
Ok, so step 1, get a box ^H^H^H^H^H I mean get the OpenSSL and NGINX sources. You want the mainline version of nginx (currently nginx-1.11.7) and OpenSSL 1.0.2 or newer.
We also need to have the “Development Tools” group installed on our system.
We can verify that nginx is now compiled against openssl-1.1.0c by running the command
Now we need an init script. There is a sample script provided on nginx.com. Save this as
/etc/init.d/nginx and then make it executable. If you want nginx to start with the system you’ll need to enable it using systemctl also. Finally, you need to allow ports 80 (http) and 443 (https) through the system firewall.
NGINX Blog - Supporting HTTP/2 for Google Chrome Users
NGINX Sample init Script