Which nginx-config file is enabled, /etc/nginx/conf.d/default.conf or /etc/nginx/nginx.conf?

NginxCentos6

Nginx Problem Overview


There are two config files around, /etc/nginx/conf.d/default.conf and /etc/nginx/nginx.conf, but which one is enabled? I am running CentOS6.4 and nginx/1.0.15.

Nginx Solutions


Solution 1 - Nginx

Technically, nginx.conf is all that matters, if you define every thing inside there it would still work, but to keep things organized, they use include, somewhere at the end of nginx.conf you'll see include /etc/nginx/conf.d/* and in some distros you'll also find include /etc/nginx/sites-enabled/* this is a convention to keep things organized, you create your server blocks in that conf.d or sites-enabled folder and it would be included here as if it's written in the nginx.conf file.

Of course you can add your own include lines there normally and create your own new conf folder that would be auto included.

TIP: These files are included in alphabetical order, you need to keep that in mind if you don't specify any server as default_server, because first one would be the default.

Solution 2 - Nginx

the general configuration of nginx is in /etc/nginx/nginx.conf. /etc/nginx/conf.d/default.conf is used to configure the default virtual host. For this you can also use sites-available and sites-enabled.

You can find more details at a blog entry from digital ocean How To Configure The Nginx Web Server On a Virtual Private Server

Solution 3 - Nginx

for save time.

  • if you just have 1 site to host, nginx.conf is ok. but,
  • if you have 2~n sites, for more clear config, you should use conf.d fold.

detail.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDerekView Question on Stackoverflow
Solution 1 - NginxMohammad AbuShadyView Answer on Stackoverflow
Solution 2 - NginxpeterView Answer on Stackoverflow
Solution 3 - Nginxrogers.wangView Answer on Stackoverflow