Written by James McDonald

June 16, 2017

Install python3. This is for CentOS

yum install python34

Download and install nginxfmt.py. The download and the instructions are at https://github.com/1connect/nginx-config-formatter

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
nginxfmt.py *.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…

Meraki Open Source Licenses

Until today I assumed that Meraki was built in-house with only closed source software. But having a look at the...


If you have Veeam backup failing with the Updating BCD failed with Cannot update SafeBoot flag and SentinelOne is...