Score:0

nginx on Debian Buster: The right way to handle Config-Files?

ps flag

Nginx can be configured via various configuration files:

  • *.conf-Files inside /etc/ngninx/conf.d
  • *.conf-Files inside /etc/nginx/sites-available
  • Last but not least: /etc/nginx/sites-available/default

Can anyone shed some light on when to use which file correctly for which application scenario? The documentation only says how config files should look like, but not how to store them where.

sv flag
I configured Debian Buster a couple of days ago on Google Cloud. I don't find `/etc/nginx/sites-available` by default. My `/etc/nginx/nginx.conf` includes only `/etc/nginx/conf.d/*.conf;`. Please post your config using the output of `nginx -T`. Thanks.
us flag
Most likely you didn't use Debian packaged version of nginx, because it definitely has `sites-available` / `sites-enabled` mechanism.
sv flag
Probably, Google has modified the default in Debian, like they do with most other software and OS in their platform.
Score:0
in flag

If you do not care about best practices, you can take a look at nginx.conf and see which directory is included. It will probably be nginx/conf.d/*.conf, so you can store your configs there and they will work after restarting (or reloading) the nginx service.

However I will try to answer simply with the standard nginx approach, regardless of the distro:

nginx comes with the nginx.conf file inside /etc/nginx. There you have a block, which tells nginx to read additional .conf files from the directory conf.d.

*.conf-Files inside /etc/ngninx/conf.d This is the default directory, which nginx creates after installation. It is used to store virtual host configurations in the *.conf format. However, this is not the best approach.

*.conf-Files inside /etc/nginx/sites-available A more elegant approach is to have the .conf file of your virtual host situated in sites-available.

*.conf-Files inside /etc/nginx/sites-enabled This is where you would symlink the virtual hosts from sites-available, to make nginx read and work with them.

For this approach to work, you would need to edit nginx.conf and have it serve conf files from sites-enabled. After that, in order to add a new vhost to nginx, just create a symlink.

ln -s /etc/nginx/sites-available/mycoolsite.conf /etc/nginx/sites-enabled/mycoolsite.conf

Restart nginx and you're all done. mycoolsite will now be served by nginx

service nginx restart
Michael Hampton avatar
cz flag
Note that the sites-available/sites-enabled is not a standard nginx approach. It is a Debian specific approach (of dubious utility these days).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.