Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginx scripts for enable and disabling a site. This will create or destroy a symlink between a real config file in /etc/nginx/sites-available and a symlink in /etc/nginx/sites-enabled.
#!/usr/bin/env bash
if [ $EUID -ne 0 ]; then
echo "You must be root: \"sudo ngxdis\""
exit 1
fi
# -z str: Returns True if the length of str is equal to zero.
if [ -z "$1" ]; then
echo "Please choose a site."
exit 1
else
echo "Disabling site $1..."
# -h filename: True if file exists and is a symbolic link.
# -f filename: Returns True if file, filename is an ordinary file.
if [ ! -h "/etc/nginx/sites-enabled/$1" ] && [ ! -f "/etc/nginx/sites-enabled/$1" ]; then
echo "$1 is not enabled."
exit 1
else
rm /etc/nginx/sites-enabled/$1
echo "Disabled $1"
fi
fi
#!/usr/bin/env bash
if [ $EUID -ne 0 ]; then
echo "You must be root: \"sudo ngxen\""
exit 1
fi
# -z str: Returns True if the length of str is equal to zero.
if [ -z "$1" ]; then
echo "Please choose a site."
exit 1
else
echo "Enabling site $1..."
# -h filename: True if file exists and is a symbolic link.
# -f filename: Returns True if file, filename is an ordinary file.
if [ -h "/etc/nginx/sites-enabled/$1" ] || [ -f "/etc/nginx/sites-enabled/$1" ]; then
echo "$1 is already enabled."
exit 1
else
if [ ! -f "/etc/nginx/sites-available/$1" ]; then
echo "Site $1 does not exist in /etc/nginx/sites-available."
exit 1
else
ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/$1
echo "Enabled $1"
exit 0
fi
fi
fi
@lucasltv
Copy link

lucasltv commented Feb 20, 2021

Thank you bro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment