Nginx with full HTTP/2 support on Centos 7


Getting sweet HTTP/2 support with TLS encryption and ALPN on nginx involves compiling nginx version above 1.9.5 with OpenSSL version above 1.0.2.

OpenSSL with required version will be available in Centos from version 7.4, but we want it now.


  • Centos 7 minimal install
  • suggested: domain with TLS certificate attached in nginx config

nginx install script (thanks to

Script assume current user has root privileges.

yum -y groupinstall 'Development Tools'
yum -y install wget openssl-devel libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel rpmdevtools


rpm -ivh$NGINX_VERSION.el7.ngx.src.rpm
rpm -ivh$NGINX_VERSION.el7.ngx.src.rpm
rpm -ivh$NGINX_VERSION.el7.ngx.src.rpm
rpm -ivh$NJS_VERSION.el7.ngx.src.rpm
rpm -ivh$NGINX_VERSION.el7.ngx.src.rpm
rpm -ivh$NGINX_VERSION.el7.ngx.src.rpm

sed -i "/Source12: .*/a Source100:$OPENSSL.tar.gz" /root/rpmbuild/SPECS/nginx.spec
sed -i "s|--with-http_ssl_module|--with-http_ssl_module --with-openssl=$OPENSSL|g" /root/rpmbuild/SPECS/nginx.spec
sed -i '/%setup -q/a tar zxf %{SOURCE100}' /root/rpmbuild/SPECS/nginx.spec
sed -i '/.*Requires: openssl.*/d' /root/rpmbuild/SPECS/nginx.spec
sed -i 's|%define WITH_LD_OPT .*|%define WITH_LD_OPT ""|g' /root/rpmbuild/SPECS/nginx.spec
sed -i 's| -fPIC||g' /root/rpmbuild/SPECS/nginx.spec

spectool -g -R /root/rpmbuild/SPECS/nginx.spec

rpmbuild -ba /root/rpmbuild/SPECS/nginx.spec
rpmbuild -ba /root/rpmbuild/SPECS/nginx-module-geoip.spec
rpmbuild -ba /root/rpmbuild/SPECS/nginx-module-image-filter.spec
rpmbuild -ba /root/rpmbuild/SPECS/nginx-module-njs.spec
rpmbuild -ba /root/rpmbuild/SPECS/nginx-module-perl.spec
rpmbuild -ba /root/rpmbuild/SPECS/nginx-module-xslt.spec

rpm -Uvh /root/rpmbuild/RPMS/x86_64/nginx-$NGINX_VERSION.el7.centos.ngx.x86_64.rpm

All that is left is adding http2 to listen segment in nginx config:

listen 443 http2;

Restart the server with

systemctl restart nginx.service

and you can enjoy nginx with HTTP/2 and ALPN on Centos7.