Skip to content

Instantly share code, notes, and snippets.

@arashm
Created August 27, 2016 15:26
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 arashm/c85c00c92d1daf0e5f10510550d797fe to your computer and use it in GitHub Desktop.
Save arashm/c85c00c92d1daf0e5f10510550d797fe to your computer and use it in GitHub Desktop.
A simple script to change the current enabled config of nginx
function nginx-enable --argument-names config_name -d "enable the given nginx config"
set nginx_conf_path "/etc/nginx"
set available_directory "servers-available"
set enabled_directory "servers-enabled"
if test ! -n "$config_name"
echo "No config is given."
return
end
if test -e "$nginx_conf_path/$enabled_directory/$config_name"
echo "This config is already enabled."
return
end
if test ! -e "$nginx_conf_path/$available_directory/$config_name"
echo "The given config doesn't exist."
return
end
echo "####"
echo "Enabling \"$config_name\""
echo "####"
sudo rm $nginx_conf_path/$enabled_directory/*
sudo ln -s "$nginx_conf_path/$available_directory/$config_name" "$nginx_conf_path/$enabled_directory/$config_name"
echo "Config file copied. Reloading nginx:"
sudo nginx -s reload
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment