0

I'm struggling to figure out the meaning of each nginx configuration file located in different directories. So far I've found these directories/files related:

  • /etc/nginx/nginx.conf - this is the main file that nginx will read. It also has several include directives to reference configurations defined in several other files.
  • /etc/nginx/conf.d/*.conf - in my default installation, there's one default.conf file at this location. Is this the one that I should go to edit if I want to, for example, add my own website?
  • /etc/nginx/sites-available - Sometimes there's a file named 'default' here. What is this directory for and what's this configuration file? What's its relationship with the default.conf file under conf.d?
  • /etc/nginx/sites-enabled - Another confusion. What's this directory then? And on my installation I see a symbolic link file pointing to the 'default' file in the sites-available directory. What's the point of doing this, separating into 2 directories but link them by some means?
Nico
  • 497
  • 1
  • 4
  • 15
  • you store your site configurations in `/etc/nginx/sites-available`, now if you want to enable that website so the user can access it, you put it in `/etc/nginx/sites-enabled`. The `default` is normally a config file that holds config for default vhost. It is genrally better to make a different config file for each vhost you deploy, so you can manage them easier. – Bijay Regmi Feb 25 '22 at 01:48
  • After posting this I did some research and found that the sites-enabled and -available mechanism has been announced deprecated. So what's the new recommended way, which I guess should be more straightforward and simpler? – Nico Feb 25 '22 at 06:04
  • Well, you can always combine everything inside `nginx.conf` and ignore the other files - but they are there to reduce your cognitive load and split the potentially big config into smaller and more easily maintainable chunks. You may have 12 sites configured inside `/etc/nginx/sites-available` - but make only 3 of them **active** with the help of `/etc/nginx/sites-enabled` – IVO GELOV Feb 25 '22 at 07:05
  • If you have a complex configuration with lots of websites, split them across many files. If you have a simple configuration with one or two websites, put everything into `/etc/nginx/nginx.conf` and remove the `include` directives pointing to other directories. Do whatever is best for your site. – Richard Smith Feb 25 '22 at 11:06
  • Also, I personally recommend naming each site config in `sites-enabled` as their fqdn for e.g `/etc/nginx/sites-enabled/mydomain.org`, `/etc/nginx/sites-enabled/subdomain.mydomain.org` etc. This will help you change your config per site easily and debug easily incase you need to. – Bijay Regmi Feb 25 '22 at 12:51
  • Thanks all for sharing the knowledge about sites-enabled and sites-available. I also found https://stackoverflow.com/a/64438763/702388 this one helpful. – Nico Feb 26 '22 at 01:53

0 Answers0