Skip to content

Instantly share code, notes, and snippets.

@oca159
Forked from ljfauscett/nginx-site.sh
Created February 18, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oca159/84187e25bd00cd58fbfe087d044df1fa to your computer and use it in GitHub Desktop.
Save oca159/84187e25bd00cd58fbfe087d044df1fa to your computer and use it in GitHub Desktop.
nginx enable/disable sites
#!/bin/bash
SITES_AVAILABLE_DIR=/etc/nginx/sites-available
SITES_ENABLED_DIR=/etc/nginx/sites-enabled
function print_usage() {
echo "nginx-site -e <site name> to enable"
echo "nginx-site -d <site name> to disable"
}
if [ $# -ne 2 ]; then
print_usage
exit 1
elif [ $1 != "-e" ] && [ $1 != "-d" ]; then
print_usage
exit 1
else
SITE_AVAILABLE="$SITES_AVAILABLE_DIR/$2"
SITE_ENABLED="$SITES_ENABLED_DIR/$2"
fi
if [ $1 == "-e" ]; then
if [ ! -e $SITE_AVAILABLE ]; then
echo "$2 does not exist."
exit 0
fi
if [ -h $SITE_ENABLED ]; then
echo "$2 is already enabled."
exit 0
else
ln -s $SITE_AVAILABLE $SITE_ENABLED
echo "$2 has been enabled. Restart nginx."
fi
fi
if [ $1 == "-d" ]; then
if [ ! -h $SITE_ENABLED ]; then
echo "$2 is not enabled."
exit 0
else
rm $SITE_ENABLED
echo "$2 has been disabled. Restart nginx."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment