Forum: NGINX Multiple client_max_body_size (location based)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Juan Fco. Giordana (Guest)
on 2009-01-13 12:19
(Received via mailing list)
Hello,

Is it possible to have multiple client_max_body_size per location
directives?

I've tried this and doesn't seem to work, but the docs says that it is
possible to have client_max_body_size in a location context.

I'm using nginx-0.6.34.

server {
     client_max_body_size 1m;

     location = upload-image.php {
         client_max_body_size 3m;
     }

     location = upload-file.php {
         client_max_body_size 10m;
     }
}

Thanks!
Igor S. (Guest)
on 2009-01-13 12:22
(Received via mailing list)
On Tue, Jan 13, 2009 at 08:07:02AM -0200, Juan Fco. Giordana wrote:

> server {
>     client_max_body_size 1m;
>
>     location = upload-image.php {
>         client_max_body_size 3m;
>     }
>
>     location = upload-file.php {
>         client_max_body_size 10m;
>     }
> }

Yes, it's possible, however, you should correct your locations:

-     location = upload-image.php {
+     location = /upload-image.php {
Juan Fco. Giordana (Guest)
on 2009-01-13 13:24
(Received via mailing list)
Thank you very much Igor,

It seems that I forgot something while doing the combinations :)

I have another question that is more or less related to this subject
too: Is there a way to avoid entering over and over the fastcgi
parammeters?, this would be excluding the usage of the include directive
since the effect would be the same as typing everything.

server {
     [...]
     client_max_body_size 1m;
     [...]

     location ~ \.php$ {
         try_files $uri @sitename;

         fastcgi_pass  127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME
/path/to/www/$fastcgi_script_name;
         include fastcgi_params;
     }

     location = /upload-file.php {
         client_max_body_size 15m;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_param SCRIPT_FILENAME
/path/to/www/$fastcgi_script_name;
         include fastcgi_params;
     }

     location = /upload-image.php {
         client_max_body_size 2m;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_param SCRIPT_FILENAME
/path/to/www/$fastcgi_script_name;
         include fastcgi_params;
     }

     location @sitename {
         # Avoid Link Rot.
         rewrite ^/aboutus\.php$       /about/ permanent;
         rewrite ^/activate\.php$      /signup/activate/ permanent;
         rewrite ^/something\.php$     /else/ permanent;

         fastcgi_pass 127.0.0.1:9000;
         fastcgi_param SCRIPT_FILENAME /path/to/www/rewrite.php;
         include fastcgi_params;
     }
}

Thanks again.
Igor S. (Guest)
on 2009-01-13 14:15
(Received via mailing list)
On Tue, Jan 13, 2009 at 09:14:28AM -0200, Juan Fco. Giordana wrote:

> Thank you very much Igor,
>
> It seems that I forgot something while doing the combinations :)
>
> I have another question that is more or less related to this subject
> too: Is there a way to avoid entering over and over the fastcgi
> parammeters?, this would be excluding the usage of the include directive
> since the effect would be the same as typing everything.

You may set common fastcgi_param's on http or server level.
However, any fastcgi_param overrides inherited fastcgi_param's,
so you need to set all fastcgi_param's in @sitename.

You do not need
     fastcgi_index index.php;
in
     location ~ \.php$ {
as fastcgi_index is required for "/dir/" requests which never match
"\.php$".

Also, I has moved rewrite's to exact locations.

server {
     [...]
     client_max_body_size 1m;
     [...]

     fastcgi_param SCRIPT_FILENAME /path/to/www/$fastcgi_script_name;
     include fastcgi_params;

     location ~ \.php$ {
         try_files $uri @sitename;

         fastcgi_pass  127.0.0.1:9000;
     }

     location = /upload-file.php {
         client_max_body_size 15m;
         fastcgi_pass 127.0.0.1:9000;
     }

     location = /upload-image.php {
         client_max_body_size 2m;
         fastcgi_pass 127.0.0.1:9000;
     }

     location @sitename {
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_param SCRIPT_FILENAME /path/to/www/rewrite.php;
         include fastcgi_params;
     }

     location = /aboutus.php {
         rewrite ^      /about/  permanent;
     }

     location = /activate.php {
         rewrite ^      /signup/activate/  permanent;
     }

     location = /something.php {
         rewrite ^      /else/  permanent;
     }
Juan Fco. Giordana (Guest)
on 2009-01-14 01:14
(Received via mailing list)
Thanks again Igor,

Everything works as expected.

The app I'm working on still needs fatcgi_index but I've moved it to the
right location (server context).

Igor S. wrote:
> Also, I has moved rewrite's to exact locations.
This topic is locked and can not be replied to.