Nginx – How to Enable Site Command in Nginx

commandcommand-line-interfacenginxwebsite

We all know how to enable a website using apache on Linux.
I'm pretty sure that we all agree on using the a2ensite command.

Unfortunately, there is no default equivalent command that comes with Nginx, but it did happen that I installed some package on ubuntu that allowed me to enable/disable sites and list them.

The problem is I don't remember the name of this package.

Does anybody know what I'm talking about?

Please tell me the name of this package and the command name.

Best Answer

If you have installed the nginx package from the Ubuntu repositories, you will have two directories.

/etc/nginx/sites-enabled and /etc/nginx/sites-available.

In the main nginx configuration, /etc/nginx/nginx.conf, you have the following line:

include /etc/nginx/sites-enabled/*.conf;

So basically to list all available virtualhosts, you can run the following command:

ls /etc/nginx/sites-available

To activate one of them, run the following command:

ln -s /etc/nginx/sites-available/www.example.org.conf /etc/nginx/sites-enabled/

The scripts that comes with Apache is basically just simple shell wrappers that does something similar as above.

After linking the files, remember to run sudo service nginx reload/ service nginx reload