Home > Software design >  Nginx rewrites parent rules with same key in sub-files?
Nginx rewrites parent rules with same key in sub-files?

Time:11-09

Accessing the /etc/nginx/nginx.conf file I have the following rule:

server {}
http {

    access_log   logs/access.log  main;
    error_log    logs/error.log  error;

    include /etc/nginx/conf.d/*.conf;

In another file, called etc/nginx/conf.d/custom.conf, I have the code:

http {
    blablabla …

When NGINX loads the settings, will the HTTP code block that was inside NGINX.CONF be “merged” with the settings included below or will it simply be replaced?

In this scenario for example, will the LOGS continue to be saved in the folder even if CUSTOM.CONF doesn't implement anything about it?

My current issue: I can't see the logs that should be printed in the error/access.log files, remembering that my application is generating a 500 HTTP error.

CodePudding user response:

Even if you can have more then a single http block you should not do it. But having an http block in another http block IS NOT ALLOWED and will raise an error on startup. Just tested this on my instance. So you should check the output of nginx -T and check the configuration.

The NGINX configuration works in an hierarchical order. Means a directive you set in the http context can be overwritten in the server or location context if supported.

  • Related