Multiple client_max_body_size (location based)

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!

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 {

Thank you very much Igor,

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

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.

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 :slight_smile:

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;
 }

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.