Do nginx.conf files in sites-available inherit from /etc/nginx/nginx.conf

Posted February 21, 2016 23.5k views

At the moment I am not creating an http block in my custom nginx.conf files that I am placing in sites-available.

If I do not create an http block in my files, does my file inherit from nginx.conf location in /etc/nginx/nginx.conf

I noticed at the bottom of the /etc/nginx/nginx.conf that this file includes the files that are in in sites-enabled, so I am guessing it does? If this is the case, what happens if I declare an http block in my app specific nginx.conf file? Will it ignore the default configuration from /etc/nginx/nginx.conf?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

As far as I know, nginx looks for nginx.conf in the root folder of nginx, not in sites-available, there shouldn’t even be a nginx.conf in that folder, maybe its a backup?

  • My apologies. I meant to say sites-enabled. In my /etc/nginx/nginx.conf file, at the very end it includes this line: include /etc/nginx/sites-enabled/*;

    Does this mean that the nginx config file I symlinked from sites-available to sites-enabled is included in the root nginx.conf file?

    This nginx.conf file was created by the Phusion Passenger/Nginx install and not the general nginx install.

    • I do not know what you wish to do, there is no reason to have multiple http blocks. But… As far as I understand it, if you have a=1 and b=2 in nginx.conf and you put b=4 and c=3 in sites-enabled/*; nginx will read it as a=1, b=4 and c=3, everything down the line overwrites everything that is before it. This is based on my experience, how exactly it works I cannot find anywhere :/