Extract all the server names from nginx configs

Let's say you have a bunch of sites behind one nginx, and you want to extract all the domains from all the .conf files, one per line. #shell

cd /etc/nginx/sites-enabled
cat * | grep server_name | sed "s/server_name//" | tr -d ";" | cut -f1 -d"#" | xargs | tr " " "\n" | sort | uniq

Explanation

Voila!


Unless specified otherwise, this work is licensed under a Creative Commons BY-NC-SA 4.0.