Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an /admin catalog on my website and I would like to allow admins to upload large files via web forms. Here is how my looks:

http {
    # ...
    client_max_body_size 16M;
    # ...

    server {
        root /var/www/;
        index index.php;

        location /admin {
            client_max_body_size 256M;

        # ...

This does not work. /admin/index.php script cannot upload files larger that 16Mb: 413 Request Entity Too Large

However, if I move client_max_body_size to server block everything works fine. But I wouldn't want to make this change only for admin catalog.

According to docs, client_max_body_size can be placed inside location block to override setting only for desired path.

What could be wrong?

share|improve this question
up vote 9 down vote accepted

It works just fine, the problem is you have misunderstood how locations work. Nginx will only ever apply one location block, never more than one. So when you have two locations

location ~ \.php$ and location /admin and the URI is /admin/index.php then your first location applies but the second one doesn't. Even if you were to use a rewrite within a location then nginx would discard directives and reparse them for the new location.

This is also the reason why you always post full configs so that you don't hide what's actually wrong.

share|improve this answer
Sorry, for not posting complete config, you are right. As for the answer, this can't be true. Here is the example from docs: And in other places multiple location blocks work for me just fine. – Temnovit Aug 30 '11 at 11:38
Sorry, but it's 100% right. Nginx can search through multiple location blocks, but it will only ever apply the directives of one of them. Which one it chooses depends on the rules documented on the page you linked. – Martin Fjordvald Aug 30 '11 at 15:22
thank you, I understand now. – Temnovit Oct 23 '11 at 10:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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