client_max_body_size per $request_uri

Valentin V. Bartenev ne at vbart.ru
Sat Jan 28 11:57:19 UTC 2012


On Saturday 28 January 2012 14:52:38 skyroski wrote:
> Hi, I have found similar topics on discussion with location based
> request but because I'm using a PHP software that by default handles
> everything through a single PHP file (including processing POST uploads
> of files) I would like to be able to use
> 
> if ($request_uri ~* upload$) {
>     client_max_body_size 200M;
> }
> 

If you want something like "if ($uri ..." then you should use the "location"
directive: http://www.nginx.org/en/docs/http/ngx_http_core_module.html#location

btw, http://wiki.nginx.org/IfIsEvil

[...]
> if (!-e $request_filename) {
>   rewrite ^/(.*)$ /index.php/$1 last;
>   break;
> }

Use try_files instead:
http://www.nginx.org/en/docs/http/ngx_http_core_module.html#try_files

e.g.:

    location / {
        try_files $uri @index_php;
    }

    location ~* upload$ {
        client_max_body_size 200M;
        ...
    }

    location ~ \.php$ {
        fastcgi_pass php;
        include fastcgi_params;
    }

    location @index_php {
        fastcgi_pass php;
        include fastcgi_params;
        fastcgi_param PATH_INFO   $uri;
        fastcgi_param SCRIPT_NAME /path/to/your/index.php;
    }

 wbr, Valentin V. Bartenev



More information about the nginx mailing list