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.
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.Restart nginx and you're all done. mycoolsite will now be served by nginx