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?

  • You will need two separate server blocks. I don't think there's any other way. – Grumpy Dec 20 '13 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 '13 at 21:39
  • @Grumpy good point could use includes to solve this – Sammaye Dec 20 '13 at 22:17

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;
| improve this answer | |
  • 1
    Sweet works cheers – Sammaye Dec 20 '13 at 23:18
  • this does not work as it gives "client_max_body_size" directive invalid value in ... – Muayyad Alsadi May 12 '15 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 '15 at 16:08
  • I see the same thing as muayyadalsadi. Full details: serverfault.com/questions/722249/… – Nathaniel Waisbrot Sep 14 '15 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 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.