4

I want to increase the client_max_body_size parameter for a specific location.

I tried to do something like that in the location

location / {
    proxy_pass http://dashboard-app;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_cache_bypass $http_upgrade;

    location /admin/upload {
        client_max_body_size 10m;
    }
}

the problem is that there is no proxy_pass or all other modules in the /admin/upload location, so I'm gettings 404 for that route.

I know I can just add all the modules inside that location, but it's just a duplication of code which seemds useless to me.

How can I inherit the base location modules to the upload location conf?

TomG
  • 2,409
  • 4
  • 23
  • 40
  • 1
    have to duplicate either `include` the same config – Deadooshka May 24 '17 at 08:08
  • 2
    Given the example in your question, only [`proxy_pass`](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass) and `client_max_body_size` needs to be in the new `location` - the other statements will be inherited. But the [`include` directive](http://nginx.org/en/docs/ngx_core_module.html#include) is also available to offload large chunks of repetitive statements. – Richard Smith May 24 '17 at 09:25
  • 1
    @RichardSmith why would the other modules be inherited but the `proxy_pass` won't? where can I see which modules are inherited and which are not? – TomG May 24 '17 at 10:03
  • 1
    See the references in my comment and particularly note the "context". – Richard Smith May 24 '17 at 10:06

1 Answers1

2

Which modules are inherited and which are not?

This issue is not expressed clear in the documentation. You need to check each and every directive individually.

In general, commands are not inherited, options are inherited, arrays of options ("array-type directives") are inherited but replaced at whole (for example, no way to add header in a descender, all headers will be replaced).

See: Directive Inheritance in Nested Location Blocks answer.

How to avoid code duplication?

From nginx side only include directive can be used for that. Also, a recommended way is to use third party tools (e.g. template engines) to generate nginx config from a concise source.

ruvim
  • 7,151
  • 2
  • 27
  • 36