Nginx set a variable conditionally

I want to allow 1GB uploads on a specific subdomain of my site called upload.xxx.xx.xx.

Currently I am trying something like:

server {
    if ( $host = 'upload.xxx.xx.xx' ) {
           client_max_body_size 1000M;
    }
}

But of course it gives me an error about the client_max_body_size not supposed to be there.

Is there a way to accomplish what I want without duplicating the two vhosts, all the settings are the same otherwise, or on the flip side should I not bother to go to the trouble of making sure the user can only upload greater than 10MB on upload subdomain?


Solution 1:

I'm not sure whether it works specifically with client_max_body_size, but, in general, nginx does allow to do exactly what you describe.

server {
    set $cmbs 100K;
    if ( $host = 'upload.xxx.xx.xx' ) {
           set $cmbs 1000M;
    }
    client_max_body_size $cmbs;
}