nginx_ensite and nginx_dissite for quick virtual host enabling and disabling
a2dissite is written in
a2dissite is a symbolic link to
a2ensite. Here I followed
the same approach, i.e.,
nginx_dissite is a symbolic link to
The script allows for arbitrary paths for the nginx configuration directories. This is particularly useful not only to those on Mac, but also in a microservice approach where each service has it's own vhost configuration, for example.
Th deafult startup program is
service. Feel free to pass another
program. For example using nginx to send a
SIGHUP to reload the
configuration you just pass the option
-s nginx to the script.
Just drop the script and the symbolic link in
/usr/sbin or other
location appropriate for your system. Meaning:
cp nginx_* /usr/sbin.
That's it you're done.
Note that the script assumes a specific file system topology for your
nginx configuration. Here's the rundown:
All virtual hosts configuration files are by default under
/etc/nginx/sites-available. For example the virtual host
foobaris configured through a file in
After running the script with
nginx_ensite foobar. A symbolic link
/etc/nginx/sites-enabled/foobar -> /etc/nginx/sites-available/foobaris created. Note that if the
/etc/nginx/sites-enableddirectory doesn't exist the script creates it.
The script invokes
nginx -tto test if the configuration is correct. If the test fails no symbolic link is created and an error is signaled.
If everything is correct now just reload nginx, in Debian based systems that means invoking
service nginx reload(default startup program name is
Now point the browser to the newly configured host and everything should work properly assuming your configuration is sensible.
To disable the site just run
nginx_dissite foobar. Reload nginx to update the running environment.
The script is written in Bash and uses what I believe to be some Bash specific idioms. I never tested it in other shells. You're welcomed to try it in any other shell. Please do tell me how it went.
It requires also awk. The original
awk (usually called BWK awk) from Bell Labs will do if you don't
have gawk (Gnu awk). IN OS X and
*BSD the former is the default
awk. The script should work in *BSD,
OS X and GNU/Linux.
There's a Bash script for automatic completion of sites to be
enabled and disabled located in the
To make use of it you should:
Source the script to Bash by issuing either
Now when you invoke
nginx_ensitethe sites under
/etc/nginx/sites-availablewill appear as hypothesis for completion. For
nginx_dissiteyou get all the sites listed in
/etc/nginx/sites-enabledas possible completions.
To get the completion script to be sourced upon login please copy it to
/etc/bash_completion.d/or whatever location your shell environment uses to place all the completion scripts.
/etc/bash_completion.d/is the location in Debian (hence also in Ubuntu) of Bash completion scripts.
Two UNIX manual pages are included in the man directory. They should
be copied to a proper directory in your system. Something along the
Here's an online version of the manpage.
Security & Trust
The script is signed with my GPG key. Just do
keys.gpg.net --recv-keys 4D722217. Verify by issuing
Thanks to the many people that have contributed to this script. You're the stuff Free Software is made of.