Home > Mobile >  nginx allow client_max_body_size for pattern
nginx allow client_max_body_size for pattern

Time:02-06

Im trying to acheive something like:

location /api/ {
    proxy_pass http://nest:3500;
    include nginxconfig.io/proxy.conf;

    if ($request_uri ~* ^/api/(a|b|e) ) {
        client_max_body_size 50m;
    }
}

but Im getting the error:

"client_max_body_size" directive is not allowed here in /etc/nginx/sites-available/cloud.conf:59

How is that possible within the location /api/ to allow client_max_body_size for specific routes?

Thanks

CodePudding user response:

How is that possible within the location /api/ to allow client_max_body_size for specific routes?

Use 2 location blocks

Other changes may be required, but just use 2 location blocks:

Either nested:

location /api/ {
    proxy_pass http://nest:3500;
    include nginxconfig.io/proxy.conf;

    location ~ ^/api/(a|b|e)/ {
        client_max_body_size 50m;
    }
}

Or not:

location /api/ {
    proxy_pass http://nest:3500;
    include nginxconfig.io/proxy.conf;
}

location ~ ^/api/(a|b|e)/ {
    client_max_body_size 50m;

    proxy_pass http://nest:3500;
    include nginxconfig.io/proxy.conf;

}

This allows greater control and avoid using if which is evil and can easily cause a lot of confusion/problems.

  • Related