Skip to content

Instantly share code, notes, and snippets.

@georgexsh
Created June 12, 2015 08:05
Show Gist options
  • Save georgexsh/733e73f4af67a0371d8a to your computer and use it in GitHub Desktop.
Save georgexsh/733e73f4af67a0371d8a to your computer and use it in GitHub Desktop.
find useless nginx config files
import os
import glob
import re
all_files = set()
for dirpath, dirnames, filenames in os.walk('.'):
for f in filenames:
dirnames[:] = [d for d in dirnames if not d.startswith('.git')]
f = os.path.join(dirpath, f)
f = os.path.relpath(f)
all_files.add(f)
I_RE = re.compile(r'include\s+(.*);', re.IGNORECASE)
all_included = set()
def inc(f):
for l in open(f):
l = l.strip()
if l.startswith('#'):
continue
m = I_RE.search(l)
if not m:
continue
i = m.group(1).strip()
if i.startswith('/etc/nginx/'):
i = i[len('/etc/nginx/'):]
#print i
if '*' in i:
l = glob.glob(i)
else:
l = [i,]
for i in l:
all_included.add(i)
inc(i)
inc('nginx.conf')
#print all_files & all_included
no_inc = all_files - all_included
no_inc.remove('nginx.conf')
no_inc.remove(__file__)
print '\n'.join(sorted(no_inc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment