Created
June 19, 2014 10:13
-
-
Save Lexty/80cacd9b3ad791b43265 to your computer and use it in GitHub Desktop.
nginx virtual host management
This file contains hidden or 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
#!/bin/bash | |
VHOSTEN="/etc/nginx/sites-enabled/" | |
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]] | |
then | |
echo 'Usage: n2dissate VHOST' | |
echo 'Disables Nginxs virtualhost VHOST.' | |
echo -e ' -h, --help\tDisplay this help' | |
exit 0 | |
elif [ -f $VHOSTEN$1 ] | |
then | |
rm $VHOSTEN$1 | |
echo "Restart Nginx now with \"/etc/init.d/nginx restart\" to enable the change!" | |
exit 0 | |
else | |
echo "Virtualhost Config not found." | |
exit 1 | |
fi |
This file contains hidden or 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
#!/bin/bash | |
VHOSTEN="/etc/nginx/sites-enabled/" | |
VHOSTAV="/etc/nginx/sites-available/" | |
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]] | |
then | |
echo 'Usage: n2ensite VHOST [-f]' | |
echo 'Enables Nginxs virtualhost VHOST [option].' | |
echo -e ' -f\t\tForce enabling VHOST' | |
echo -e ' \t\tAlways sepcify -f after VHOST!' | |
echo -e ' -h, --help\t Display this help' | |
exit 0 | |
elif [ -f $VHOSTAV$1 ] && ( [ ! -f $VHOSTEN$1 ] || [[ $2 == "-f" ]] ) | |
then | |
if nginx -t &> /dev/null | |
then | |
[[ $2 == "-f" ]] && rm $VHOSTEN$1 &> /dev/null | |
ln -s $VHOSTAV$1 $VHOSTEN$1 | |
if nginx -t &> /dev/null || [[ $2 == "-f" ]] | |
then | |
echo "Restart Nginx now with \"/etc/init.d/nginst restart\" to enable the change!" | |
exit 0 | |
else | |
rm $VHOSTEN$1 | |
echo "Error in the virtualhost config, disabled again." | |
exit 1 | |
fi | |
else | |
echo "Error in the Nginx configuration, not enabling the virtualhost." | |
exit 2 | |
fi | |
elif [ -f $VHOSTEN$1 ] | |
then | |
echo "Virtualhost already enabled." | |
exit 0 | |
else | |
echo $VHOSTAV$1 | |
echo "Virtualhost config not found." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment