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. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…