Skip to content

Commit

Permalink
prevent dynamic-modules-includes.conf being included twice
Browse files Browse the repository at this point in the history
- prevent /usr/local/nginx/conf/dynamic-modules-includes.conf from being included in /usr/local/nginx/conf/dynamic-modules.conf more than once
  • Loading branch information
centminmod committed Jul 5, 2017
1 parent 696577f commit a9c491d
Showing 1 changed file with 44 additions and 42 deletions.
86 changes: 44 additions & 42 deletions inc/nginx_configure.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,55 @@ detect_tlsonethree() {

dynamicmodule_file() {
if [ "$ngver" ]; then
NGINX_DIRINSTALL="$DIR_TMP/nginx-${ngver}"
NGINX_DIRINSTALL="$DIR_TMP/nginx-${ngver}"
else
NGINX_DIRINSTALL="$DIR_TMP/nginx-${NGINX_VERSION}"
NGINX_DIRINSTALL="$DIR_TMP/nginx-${NGINX_VERSION}"
fi
NGX_DYNAMICCHECK=$(grep 'DYNAMIC_MODULES=' "$NGINX_DIRINSTALL/auto/options")
if [ "$NGX_DYNAMICCHECK" ]; then
echo
echo "nginx dynamic module support detected"
echo
DYNAMIC_SUPPORT=y
# force disable nginx modsecurity module as it conflicts with nginx
# 1.9.11+ dynamic module builds
NGINX_MODSECURITY='n'
# create include file to load nginx dynamic modules in main context in nginx.conf
if [[ "$INITIALINSTALL" != [yY] ]]; then
rm -rf /usr/local/nginx/conf/dynamic-modules.conf
fi
touch /usr/local/nginx/conf/dynamic-modules.conf
if [ ! -f /usr/local/nginx/conf/dynamic-modules-includes.conf ]; then
touch /usr/local/nginx/conf/dynamic-modules-includes.conf
fi
echo "# place custom load_module lines in this dynamic-modules-includes.conf" >> /usr/local/nginx/conf/dynamic-modules.conf
echo "# file so that they persistent i.e. for manually dropped in dynamic modules" >> /usr/local/nginx/conf/dynamic-modules.conf
echo "include /usr/local/nginx/conf/dynamic-modules-includes.conf;" >> /usr/local/nginx/conf/dynamic-modules.conf
# setup include file /usr/local/nginx/conf/dynamic-modules.conf in nginx.conf
if [[ ! "$(grep 'dynamic-modules.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's|^pcre_jit on;|pcre_jit on;\ninclude \/usr\/local\/nginx\/conf\/dynamic-modules.conf;\n|g' /usr/local/nginx/conf/nginx.conf
sed -i 's|^pcre_jit off;|pcre_jit on;\ninclude \/usr\/local\/nginx\/conf\/dynamic-modules.conf;\n|g' /usr/local/nginx/conf/nginx.conf
fi
if [[ "$(grep 'dynamic-modules.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's|^#include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|g' /usr/local/nginx/conf/nginx.conf
fi
# custom dynamic loading module flag include sourced file
if [ -f "${CONFIGSCANBASE}/custom_nginxmodules.inc" ]; then
# default is at /etc/centminmod/custom_nginxmodules.inc
source "${CONFIGSCANBASE}/custom_nginxmodules.inc"
fi
echo
echo "nginx dynamic module support detected"
echo
DYNAMIC_SUPPORT=y
# force disable nginx modsecurity module as it conflicts with nginx
# 1.9.11+ dynamic module builds
NGINX_MODSECURITY='n'
# create include file to load nginx dynamic modules in main context in nginx.conf
if [[ "$INITIALINSTALL" != [yY] ]]; then
rm -rf /usr/local/nginx/conf/dynamic-modules.conf
fi
touch /usr/local/nginx/conf/dynamic-modules.conf
if [ ! -f /usr/local/nginx/conf/dynamic-modules-includes.conf ]; then
touch /usr/local/nginx/conf/dynamic-modules-includes.conf
fi
if [[ ! "$(grep -w 'dynamic-modules-includes.conf' /usr/local/nginx/conf/dynamic-modules.conf)" ]]; then
echo "# place custom load_module lines in this dynamic-modules-includes.conf" >> /usr/local/nginx/conf/dynamic-modules.conf
echo "# file so that they persistent i.e. for manually dropped in dynamic modules" >> /usr/local/nginx/conf/dynamic-modules.conf
echo "include /usr/local/nginx/conf/dynamic-modules-includes.conf;" >> /usr/local/nginx/conf/dynamic-modules.conf
fi
# setup include file /usr/local/nginx/conf/dynamic-modules.conf in nginx.conf
if [[ ! "$(grep 'dynamic-modules.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's|^pcre_jit on;|pcre_jit on;\ninclude \/usr\/local\/nginx\/conf\/dynamic-modules.conf;\n|g' /usr/local/nginx/conf/nginx.conf
sed -i 's|^pcre_jit off;|pcre_jit on;\ninclude \/usr\/local\/nginx\/conf\/dynamic-modules.conf;\n|g' /usr/local/nginx/conf/nginx.conf
fi
if [[ "$(grep 'dynamic-modules.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's|^#include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|g' /usr/local/nginx/conf/nginx.conf
fi
# custom dynamic loading module flag include sourced file
if [ -f "${CONFIGSCANBASE}/custom_nginxmodules.inc" ]; then
# default is at /etc/centminmod/custom_nginxmodules.inc
source "${CONFIGSCANBASE}/custom_nginxmodules.inc"
fi
else
# comment out include file /usr/local/nginx/conf/dynamic-modules.conf in nginx.conf
# in it exists and you're moving to an nginx version that doesn't support dynamic module
# loading
if [ -f /usr/local/nginx/conf/dynamic-modules.conf ]; then
if [[ "$(grep 'dynamic-modules.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's|^include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|#include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|g' /usr/local/nginx/conf/nginx.conf
fi
fi
fi # NGX_DYNAMICCHECK check
# comment out include file /usr/local/nginx/conf/dynamic-modules.conf in nginx.conf
# in it exists and you're moving to an nginx version that doesn't support dynamic module
# loading
if [ -f /usr/local/nginx/conf/dynamic-modules.conf ]; then
if [[ "$(grep 'dynamic-modules.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's|^include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|#include \/usr\/local\/nginx\/conf\/dynamic-modules.conf;|g' /usr/local/nginx/conf/nginx.conf
fi
fi
fi # NGX_DYNAMICCHECK check
}

ngx_dynamicfunction() {
Expand Down

0 comments on commit a9c491d

Please sign in to comment.