Skip to content

Instantly share code, notes, and snippets.

@lostsnow
Last active August 29, 2015 14:25
Show Gist options
  • Save lostsnow/5447beae9063708f7b06 to your computer and use it in GitHub Desktop.
Save lostsnow/5447beae9063708f7b06 to your computer and use it in GitHub Desktop.
find vhost in nginx config files
# http://lists.centos.org/pipermail/centos/2012-December/130613.html
while (<>) {
chomp();
next if (m/^\s*#/); #comment
if ($enclosed) {
if (m/}/) {$enclosed = 0;} # end found
tr/}\;//d; #remove
push @servers, split(); #anything else on line
next;
} else {
next unless m/server_name/;
if (m/{/) { $enclosed = 1;}
if (m/}/) {$enclosed = 0;} #on same line?
s/server_name//;
tr/{}\;//d ;
push @servers,split();
}
}
foreach (sort(@servers)) { print "$_\n";}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment