• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

Input Create back-ups of Nginx configuration to determine changes

mr-wolf

Silver Pleskian
Plesk Guru
Sometimes our servers stop doing what we expect them to do.
Often this is due to some automatic update that changes a config.
Sometimes it's just Plesk reverting some custom changes.

I already have some scripts in place that checks the folder /etc/postfix or /etc/dovecot for changes and that helped me a lot when troubleshooting it.

Because the Nginx config is built from many .conf files it's better to take a different approach.
I'm using the command "nginx -T" that outputs the resulting config.
When that resulting config is different than the latest stored config it will create a new one.
Using the "diff" command on these files will quickly lead you to the answer why something is now different:

ln -s /usr/local/sbin/nginx_backup /etc/cron.hourly/
cat /usr/local/sbin/nginx_backup
Code:
#!/bin/bash

FOLDER=/etc/nginx
DATESTAMP=`date +%Y-%m-%d.%H-%M`
NEWBACKUP=${FOLDER}/nginx.conf.${DATESTAMP}
TMPDIR=`mktemp -t -d ${0//*\/}.XXXXXXXXXX`
LATESTBACKUP="`ls -1t --color=none ${FOLDER}/nginx.conf.* | grep '[0-9][0-9]\-[0-9][0-9]$' | head -n1`"

nginx -T 2>/dev/null >${TMPDIR}/current
if [ -z "${LATESTBACKUP}" ] ; then
  mv ${TMPDIR}/current ${NEWBACKUP}
elif ! diff ${TMPDIR}/current ${LATESTBACKUP} 2>&1 >/dev/null ; then
  echo "Nginx configuration has changed, new one stored in ${NEWBACKUP}"
  mv ${TMPDIR}/current ${NEWBACKUP}
fi
rm -r ${TMPDIR}
 
Back
Top