Easy enabling/disabling site on NginX, using Bash Script. This is an attempt to replicate apache a2ensite
& a2dissite
feature.
Tested in official upstream package of nginx and Ubuntu derivative package.
- Autocomplete.
- Interactive menu.
- Easy [un]install script.
- Beginner friendly.
Download your copies of repository, then execute install
script located on main directory. Note that this required root user.
wget -O nginxsite.zip https://github.com/L1so/nginxsite/archive/refs/heads/main.zip
unzip -qq nginxsite.zip && rm nginxsite.zip
cd nginxsite-main && sudo ./install
Or if you prefer git clone
.
git clone https://github.com/L1so/nginxsite.git
cd nginxsite && sudo ./install
By installing, following things will happen.
- Creating directory
/etc/nginx/sites-{available,enabled}
if not exist - Modify nginx config to include
/etc/nginx/sites-available
if not already - Copying main script to
/usr/local/bin/
Just execute uninstall
script located on this repository.
sudo ./uninstall
It will remove all trace of nginxsite
.
To activate a site, replace (YOUR SITE)
with your actual site domain (located in /etc/nginx/sites-available/
).
sudo ngxensite (YOUR SITE)
To deactivate a site, replace (YOUR SITE)
with your actual site domain (located in /etc/nginx/sites-available/
).
sudo ngxdissite (YOUR SITE)
To create a site, replace (YOUR DOMAIN)
with your actual domain.
sudo ngxcreate (YOUR DOMAIN)
Running ngxcreate
without any argument will give you a prompt to enter desired site name, if you don't include tld, the script will give you .com
domain.
$ sudo ngxcreate
Please Enter a Domain Name (default TLD is .com):
examplesite
Will save a new file named /etc/nginx/sites-available/examplesite.com
To delete a site, replace (YOUR DOMAIN)
with your actual site domain.
sudo ngxdelete (YOUR DOMAIN)
Example given below.
root@mutiny:~# ngxdelete bar.co
Removing --> /etc/nginx/sites-available/bar.co
To list site, simply type ngxlist
(or ngxlist -e
to show enabled sites).