Conditionally set client_max_body_size

I'm trying to set client_max_body_size conditionally. I've followed the configuration suggested in the answer to Nginx set a variable conditionally, but it is not working for me.

The following configuration file is sufficient to reproduce:

daemon off;
worker_processes 1;
error_log /dev/stderr debug;
events {
  worker_connections 1024;
}
http {
  access_log /dev/stdout;
  server {
    listen 80;
    location /test {
      set $cmbs 1m;
      if ($arg_long) {
        set $cmbs 5m;
      }
      client_max_body_size $cmbs;
      echo $cmbs;
    }
  }
}

When I try to start Nginx with this configuration, it halts and complains

nginx: [emerg] "client_max_body_size" directive invalid value in /opt/nginx/nginx.conf:16

If I remove the offending directive, Nginx starts and I echo the set value back in the way I expect.

I am running openresty/1.7.10.1. I've also tried the above small config on nginx/1.9.4.


Solution 1:

Nginx as of version 1.9.4 does not support variable client_max_body_size.