I have searched Stack Overflow for a straight answer but have not found it. 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?
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.
It is not a must, but a best practise if you host more than one sites on your box.
It will be easier to manage by keep http context and common directives (such as ssl_dhparam, ssl_ciphers, or even gzip settings, etc.) on the nginx.conf so that it applied across all sites.
Keep site-specific server context (such as ssl-certificate, location directives, etc.) at etc/nginx/sites-available/ and name the configuration file as your-domain.conf. The file in etc/nginx/sites-enabled can be just a link to the file to the etc/nginx/sites-available.
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 filesites-enabled/default
and it runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM, thennano
will create an emergency file calleddefault.save
, inside thesites-enabled
directory. So, there will be an extra file inside thesites-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 thedefault.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 filesites-available/default.save
would have been created, but it wouldn't do any harm inside thesites-available
directory.