NGINX
If you're using one of the official upstream packages of nginx from http://nginx.org/packages/, the best way is to navigate to the /etc/nginx/conf.d
directory, and rename the affected file from having a .conf
suffix to having a different one to disable the site:
sudo mv -i /etc/nginx/conf.d/default.conf{,.off}
Or the opposite to enable it:
sudo mv -i /etc/nginx/conf.d/example.com.conf{.disabled,}
This is because the default /etc/nginx/nginx.conf
has the following include
directive:
http {
…
include /etc/nginx/conf.d/*.conf;
}
Debian/Ubuntu
However, if you're using a Debian/Ubuntu derivative, then in addition to conf.d
, you may also have the evil non-standard sites-available
and sites-enabled
directories, some files under which may be sloppily included without regard to their extension:
http {
…
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
As such, in Debian/Ubuntu, you might first have to figure out where the site config is located.
You could use the following command to get a list of all available sites by running find(1)
to find all regular files matching the given mask:
find /etc/nginx -maxdepth 2 -type f \( -path "*/conf.d/*.conf" -or -path "*/sites-*/*" \)
You could use the following command to get a list of all enabled sites:
find /etc/nginx -maxdepth 2 \( -path "*/conf.d/*.conf" -or -path "*/sites-enabled/*" \)
Then to disable/enable sites on Debian/Ubuntu:
To disable a site: if the config is in conf.d
, just rename the file to no longer have a .conf
suffix; or if in sites-enabled
, move it out of sites-enabled
.
To enable a site, the best way would be to move it to /etc/nginx/conf.d
, and rename to have a .conf
suffix.
P.S. Why do I think Debian's include /etc/nginx/sites-enabled/*;
is evil? Try editing a couple of files in that directory, and have your emacs
create the backup files (with the ~
suffix), then ask me again.