Created
July 16, 2018 21:26
-
-
Save Locoxella/1a8926a5006a6969d1ecddeed94bffa4 to your computer and use it in GitHub Desktop.
Get every server_name from every enabled site on nginx (except default _), and add it to /etc/hosts on 127.0.0.1. Not compatible with regex.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
virtualhosts=$(awk 'BEGIN { ORS=" " }; /^\s*server_name/ { for ( i=2; i <= NF; i++ ) { serveralias[$i]++ } } END { for ( server in serveralias) { print server } }' /etc/nginx/sites-enabled/* | sed 's/\;//g' | sed 's/ _//g') | |
sed -i "/127\.0\.0\.1/ s/.*/127\.0\.0\.1 localhost $virtualhosts/g" /etc/hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment