Skip to content
Permalink
Browse files

optimise nginx default gzip compression level when cloudflare zlib used

- Centmin Mod 123.09beta01 defaults to nginx compiles with cloudflare zlib performance library instead of standard zlib 1.2.11 library if you're using a 64bit cpu with SSE 4.2 and AES-NI support. If using cloudflare zlib libary, set the default gzip compression level higher instead of 5 set to 9 defaults as benchmarks show performance is still very high even with level 9 with cloudflare zlib library https://community.centminmod.com/posts/64167/
- If Cloudflare zlib library is disabled via CLOUDFLARE_ZLIBRESET='n' or auto disabled when non-64bit, non-SSE 4.2 or non-AES-NI supported cpu is detected, auto reset default nginx gzip compression level back from 9 to 5 when default new option is set CLOUDFLARE_ZLIBRESET='y'. If you do not want it to auto reset back to gzip level 9 compression, you can override this routine by setting in persistent config file /etc/centminmod/custom_config.inc the variable, CLOUDFLARE_ZLIBRESET='n' prior to recompiling nginx via centmin.sh menu option 4
  • Loading branch information...
centminmod committed Jun 11, 2018
1 parent fafb65d commit fbd5578638b2fd71b55f4917f435bd8ab55ac12e
Showing with 22 additions and 1 deletion.
  1. +2 −1 centmin.sh
  2. +1 −0 example/custom_config.inc
  3. +19 −0 inc/nginx_configure.inc
@@ -20,7 +20,7 @@ DT=$(date +"%d%m%y-%H%M%S")
branchname='123.09beta01'
SCRIPT_MAJORVER='1.2.3'
SCRIPT_MINORVER='09'
SCRIPT_INCREMENTVER='030'
SCRIPT_INCREMENTVER='031'
SCRIPT_VERSIONSHORT="${branchname}"
SCRIPT_VERSION="${SCRIPT_VERSIONSHORT}.b${SCRIPT_INCREMENTVER}"
SCRIPT_DATE='30/06/2018'
@@ -630,6 +630,7 @@ OPENSSL_TLSONETHREE='y' # whether OpenSSL 1.1.1 builds enable TLSv1.3
OPENSSL_CUSTOMPATH='/opt/openssl' # custom directory path for OpenSSL 1.0.2+
CLOUDFLARE_PATCHSSL='n' # set 'y' to implement Cloudflare's chacha20 patch https://github.com/cloudflare/sslconfig
CLOUDFLARE_ZLIB='y' # use Cloudflare optimised zlib fork https://blog.cloudflare.com/cloudflare-fights-cancer/
CLOUDFLARE_ZLIBRESET='y' # if CLOUDFLARE_ZLIB='n' set, then revert gzip compression level from 9 to 5 automatically
CLOUDFLARE_ZLIBPHP='n' # use Cloudflare optimised zlib fork for PHP-FPM zlib instead of system zlib
CLOUDFLARE_ZLIBDEBUG='n' # make install debug verbose mode
CLOUDFLARE_ZLIBVER='1.3.0'
@@ -251,6 +251,7 @@ OPENSSL_TLSONETHREE='y' # whether OpenSSL 1.1.1 builds enable TLSv1.3
OPENSSL_CUSTOMPATH='/opt/openssl' # custom directory path for OpenSSL 1.0.2+
CLOUDFLARE_PATCHSSL='n' # set 'y' to implement Cloudflare's chacha20 patch https://github.com/cloudflare/sslconfig
CLOUDFLARE_ZLIB='n' # use Cloudflare optimised zlib fork https://blog.cloudflare.com/cloudflare-fights-cancer/
CLOUDFLARE_ZLIBRESET='y' # if CLOUDFLARE_ZLIB='n' set, then revert gzip compression level from 9 to 5 automatically
CLOUDFLARE_ZLIBPHP='n' # use Cloudflare optimised zlib fork for PHP-FPM zlib instead of system zlib
CLOUDFLARE_ZLIBDEBUG='n' # make install debug verbose mode
CLOUDFLARE_ZLIBVER='1.3.0'
@@ -706,6 +706,15 @@ if [[ "$CENTOS_SEVEN" = '7' || "$CENTOS_SIX" = '6' ]]; then
if [[ "$CLOUDFLARE_ZLIB" = [yY] && "$(cat /proc/cpuinfo | grep -o 'sse4_2' | uniq)" = 'sse4_2' && "$CHECK_PCLMUL" = 'enabled' ]]; then
ZLIBCUSTOM_DIR="zlib-cloudflare-${CLOUDFLARE_ZLIBVER}"
ZLIBCUSTOM_OPT=" --with-zlib=../zlib-cloudflare-${CLOUDFLARE_ZLIBVER}"
# if using cloudflare zlib libary set the default gzip compression level higher instead of 5 set to 9
# defaults benchmarks show performance is still very high even with level 9 with cloudflare zlib library
# https://community.centminmod.com/posts/64167/
if [ -f /usr/local/nginx/conf/nginx.conf ]; then
sed -i 's|gzip_comp_level .*|gzip_comp_level 9;|' /usr/local/nginx/conf/nginx.conf
fi
if [ -f /usr/local/src/centminmod/config/nginx/nginx.conf ]; then
sed -i 's|gzip_comp_level .*|gzip_comp_level 9;|' /usr/local/src/centminmod/config/nginx/nginx.conf
fi
#ZLIBCF_OPT='-L/usr/local/zlib-cf/lib '
#ZLIBCFINC_OPT='-I/usr/local/zlib-cf/include '
# disable clang compiler and switch to gcc compiler due to clang 3.4.2 errors when enabling
@@ -722,6 +731,16 @@ if [[ "$CENTOS_SEVEN" = '7' || "$CENTOS_SIX" = '6' ]]; then
fi
fi

if [[ "$CLOUDFLARE_ZLIBRESET" = [yY] && "$CLOUDFLARE_ZLIB" != [yY] ]]; then
# if not using Cloudflare zlib library and you previously set gzip compression level to 9, reset it back to level 5
if [[ "$(grep 'gzip_comp_level 9' /usr/local/nginx/conf/nginx.conf)" && -f /usr/local/nginx/conf/nginx.conf ]]; then
sed -i 's|gzip_comp_level .*|gzip_comp_level 5;|' /usr/local/nginx/conf/nginx.conf
fi
if [[ "$(grep 'gzip_comp_level 9' /usr/local/src/centminmod/config/nginx/nginx.conf)" && -f /usr/local/src/centminmod/config/nginx/nginx.conf ]]; then
sed -i 's|gzip_comp_level .*|gzip_comp_level 5;|' /usr/local/src/centminmod/config/nginx/nginx.conf
fi
fi

if [[ "$NGINX_OPENRESTY" = [yY] ]]; then
MEMCDIR=$(tar -tzf "$DIR_TMP/${NGX_MEMCLINKFILE}" | head -1 | cut -f1 -d"/")
SRCACHEDIR=$(tar -tzf "$DIR_TMP/${NGX_SRCACHELINKFILE}" | head -1 | cut -f1 -d"/")

0 comments on commit fbd5578

Please sign in to comment.
You can’t perform that action at this time.