The End of Ye Olde Ugly NGinx Config Files

Written by James McDonald

June 16, 2017

Install python3. This is for CentOS

yum install python34

Download and install The download and the instructions are at

Once installed usage is as follows.

# do a backup
tar -czvf nginx-conf-backup.tar.gz /etc/nginx/conf.d

cd /etc/nginx/conf.d

# warning this does an inplace edit *.conf

A word of warning. If you have code like the following which is using {} to escape a variable

if ( $remote_addr != ) {
        set $check G;
if ( -f $document_root/maintenance.html){
                set $check "${check}O";
if ( $check = GO ) {
        return 503;

It will screw it up because of the brackets as follows. But it isn’t a problem to manually fix it after the formatting is done. When you restart nginx it will complain of the bad format so you will know you need to look for this sort of gotcha

if ( -f $document_root/maintenance.html) {
        set $check "$ {



Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language The above website has a page where you can enter ZPL and it...

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...

PHP array_map Multiple Arrays

array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each...