Skip to content

Instantly share code, notes, and snippets.

@dragolabs
Last active January 17, 2019 11:08
Show Gist options
  • Save dragolabs/89f531c03682bf249e0e7b6fd657ae8e to your computer and use it in GitHub Desktop.
Save dragolabs/89f531c03682bf249e0e7b6fd657ae8e to your computer and use it in GitHub Desktop.
Show all server_names from nginx configuration
nginx -T 2>/dev/null | \
sed -r -e 's/[ \t]*$//' -e 's/^[ \t]*//' -e 's/^#.*$//' -e 's/[ \t]*#.*$//' -e '/^$/d' | \
sed -e ':a;N;$!ba;s/\([^;\{\}]\)\n/\1 /g' | \
grep -P 'server_name[ \t]' | grep -v '\$' | \
grep '\.' | \
sed -r -e 's/(\S)[ \t]+(\S)/\1\n\2/g' -e 's/[\t ]//g' -e 's/;//' -e 's/server_name//' | \
sort | uniq | xargs -L1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment