11

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?

3
  • You will need two separate server blocks. I don't think there's any other way.
    – Grumpy
    Dec 20, 2013 at 21:31
  • If you just don't want repetition of lines, you could use include to duplicate configuration without duplicating lines.
    – Grumpy
    Dec 20, 2013 at 21:39
  • @Grumpy good point could use includes to solve this
    – Sammaye
    Dec 20, 2013 at 22:17

1 Answer 1

16

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;
}
5
  • 1
    Sweet works cheers
    – Sammaye
    Dec 20, 2013 at 23:18
  • 1
    this does not work as it gives "client_max_body_size" directive invalid value in ... May 12, 2015 at 0:02
  • @muayyadalsadi, i doubt this has gotten broken since having been tested by the OP; but feel free to post another question with complete details and what you use in the config, and reference it here, we'll take a look
    – cnst
    May 12, 2015 at 16:08
  • I see the same thing as muayyadalsadi. Full details: serverfault.com/questions/722249/… Sep 14, 2015 at 18:47
  • Maybe you can solve this by defining an upstream and use proxy_pass to redirect at the right condition?
    – rubo77
    Jun 3, 2020 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .