Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx - Do I really need sites-available and sites-enabled folders?

Tags:

nginx

I noticed my install of nginx has three folders called

etc/nginx/sites-available etc/nginx/sites-enabled etc/nginx/conf.d 

Do I really need these if I just want to work directly in the etc/nginx/nginx.conf file and remove the include lines that include these items in nginx.conf? Are these directories used for anything else that would mess things up if I delete them?

like image 236
Shawn Cooke Avatar asked Dec 23 '16 15:12

Shawn Cooke


People also ask

Should I edit sites-enabled or sites available?

Important information. If you are still using sites-available/sites-enabled pattern, you should edit files only in the sites-available directory. Never edit files inside the sites-enabled directory. Otherwise you can have problems if your editor runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM.

What is sites available and sites-enabled nginx?

💡 Nginx on Linux makes use of symlinks in a smart way to enable site configurations. 👉🏼 "sites-available" folder holds all your site configurations. In the "sites-enabled" folder you create symlinks to the previous folder for the sites you wish to enable.

What is Conf d directory in nginx?

conf and for NGINX Plus is placed in the /etc/nginx directory. (For NGINX Open Source , the location depends on the package system used to install NGINX and the operating system. It is typically one of /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.)

What is ETC nginx sites-enabled default?

/etc/nginx/sites-enabled/default is the path given to the default website for Debian based systems. They are usually links to files contained /etc/nginx/sites-available . /etc/nginx/conf. d is a path used in most configurations including Debian derivatives like Ubuntu and other distro's like CentOS etc.


2 Answers

No, they are not needed if you define your server blocks properly in nginx.conf, but it's highly suggested. As you noticed, they are only used because of the include /etc/nginx/sites-enabled/*; in nginx.conf.

For curiosity, is there a reason why you do not want to use them? They are very useful; easier to add new sites, disabling sites, etc. Rather than having one large config file. This is a kind of a best practice of nginx folder layout.

like image 68
Iskar Avatar answered Sep 23 '22 14:09

Iskar


Important information:

You should edit files only in sites-available directory.

Never edit files inside the sites-enabled directory, otherwise you can have problems if your editor runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM.

For example: if you are using nano to edit the file sites-enabled/default and it runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM, then nano will create an emergency file called default.save, inside the sites-enabled directory. So, there will be an extra file inside the sites-enabled directory. That will prevent Apache or NGINX to start. If your site was working, it will not be anymore. You will have a hard time until you find out, in the logs, something related to the default.save file and, then, remove it.

In the example above, if you were editing the file inside the sites-available directory, nothing bad would have happened. The file sites-available/default.save would have been created, but it wouldn't do any harm inside the sites-available directory.

like image 42
viniciussss Avatar answered Sep 25 '22 14:09

viniciussss