Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 nginx.com looks:

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

    server {
        server_name example.com;
        root /var/www/example.com;
        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
add comment

1 Answer

up vote 8 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: wiki.nginx.org/HttpCoreModule#location And in other places multiple location blocks work for me just fine. –  Temnovit Aug 30 '11 at 11:38
1  
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
add comment

Your Answer

 
discard

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.