Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RPM build Nginx 1.11.x with ALPN on CentOS 6/7 using static OpenSSL 1.1 (v 1.02+ required for http/2 support in Chrome)
# Based on CentOS7 fork of @smartmadsoft:
# "6" for CentOS6 or Amazon Linux, "7" for CentOS7
yum clean all
# Install epel packages (required for GeoIP-devel)
yum -y install
yum -y groupinstall 'Development Tools'
yum -y install wget openssl-devel libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel pcre-devel
useradd builder
groupadd builder
mkdir -p /opt/lib
# Untar, but don't compile openssl to /opt/lib
wget$OPENSSL.tar.gz -O /opt/lib/$OPENSSL.tar.gz
tar -zxvf /opt/lib/open* -C /opt/lib
# Build source nginx (no auto-updates), statically link to /opt/lib/openssl* (no OS effects)
rpm -ivh$CENTVER/SRPMS/$NGINX.el$CENTVER.ngx.src.rpm
sed -i "s|--with-http_ssl_module|--with-http_ssl_module --with-openssl=/opt/lib/$OPENSSL|g" /root/rpmbuild/SPECS/nginx.spec
# Compile it
rpmbuild -ba /root/rpmbuild/SPECS/nginx.spec
# Install it
rpm -ivh /root/rpmbuild/RPMS/x86_64/$NGINX.el$CENTVER.ngx.x86_64.rpm
mkdir -p /etc/nginx/ssl
# You can just accept defaults, but make sure to use a "real" local dev Common Name, eg: localdev
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
# *** Add /etc/hosts on OSX for localhost (eg, localdev )
cp -p /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf-orig
cat <<'EOT' > /etc/nginx/conf.d/default.conf
server {
listen 80 default_server;
listen 443 ssl http2;
root /usr/share/nginx/html;
index index.html index.htm;
# LOCALDEV-COMMON-NAME is whatever you gave in the certificate setup for Common Name
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
location / {
try_files $uri $uri/ =404;
/opt/lib/openssl*/apps/openssl version -a
nginx -V # 2>&1 | sed -r -e 's/\s+--/\n/g' | grep -E 'version|v2' --color=never
# service iptables stop # <-- only for VirtualBox setups
service nginx start
# Other useful queries:
# /opt/lib/openssl*/apps/openssl ciphers | tr ':' '\n' | sort | less
# /opt/lib/openssl*/apps/openssl ecparam -list_curves | less

This comment has been minimized.

Copy link

maszd commented Apr 2, 2017

Hi @kennwhite, please add an option to add headers_more_nginx module.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.