Fragmenting one big nginx config
Getting lost in all glory of big nginx.conf is not that uncommon. I could not stand it anymore, so I wrote this little clever script with support of pyparsing module for Python: from pyparsing import * nginx_conf_expr = OneOrMore(Suppress(SkipTo('server' + White())) + originalTextFor(Word('server ') + nestedExpr('{', '}'))).parseWithTabs() server_name_expr = (Suppress(SkipTo('server_name' + White()) + Word('server_name') + White()) + CharsNotIn(' ;')).parseWithTabs() nginx_conf = open('nginx.conf').read() new_nginx_conf = str(nginx_conf) for server in nginx_conf_expr.parseString(nginx_conf): ...