Search code examples
sslnginxwebserver

Understanding nginx config file structure


I am fairly new to nginx. After I installed everything, I noticed that I am not quite sure, which conf file will be used. I have those config files:

  • /etc/nginx/nginx.conf
  • /etc/nginx/nginx.conf.default
  • /etc/nginx/conf.d/ssl.conf

Here is what I am trying to do:

  • mydomain.com --> use ssl certificate and load a index.html
  • sub.mydomain.com --> use ssl certificate and load a index.html in a different folder
  • redirect http requests to https

So, what are the differences between the three config files? Which one is the "active" one (which one is "applied")? I created the ssl.conf by following this tutorial, but I still don't get the "idea behind it".


Solution

  • The file /etc/nginx/nginx.conf is the nginx configuration file. Any other files or directories used to construct the final configuration must be explicitly referenced from within that file, either directly or indirectly using the include directive. See this document for details.

    There are a number of conventions out there, but you can choose to put everything into a single file, or split out servers and common configuration into separate files.