0

My environments :
- Backend application running with Symfony 2
- Nginx 1.8.0
- Centos 6.5
- php-fpm

Here is my nginx conf :

server {
    listen 443;
    server_name demo.example.com;
    root /usr/share/nginx/html/crowdfunding/web;

    ssl on;
    ssl_certificate /etc/nginx/ssl/xxxxx.crt;
    ssl_certificate_key /etc/nginx/ssl/xxxxx.key;

    recursive_error_pages off;
    error_page 413 = $uri/413;

    error_log /var/log/nginx/example_error.log;
    access_log /var/log/nginx/example_access.log;

    location / {
        try_files $uri /app.php$is_args$args;
    }


    # PROD
    location ~ ^/app\.php(/|$) {
        internal;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_index  index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS on;
        fastcgi_intercept_errors on;
    }
}

I have a page with an upload file input : http://demo.example.com/fr/member/edit The maximum size that i want is 500ko for this image When i try to upload a 2Mo file i have this error in my error file "client intended to send too large body" then you can see on the web browser corner the upload running, when it achieve the 100% is redirect to demo.example.com/fr/member/edit and restart to upload ... until nginx prompt error (may be about time process)

What i would like :
When nginx detect this : "client intended to send too large body" then stop uploading the file and redirect to http://demo.example.com/fr/member/edit/413 (this is a route that should go into #prod) I just want to redirect a 413 to an other page of my application with nginx

Thanks for your help and ask me if you need more informations.

Update 1 : Here my symfony 2 form

$builder->add('image', 'file', array('label' => 'general.image', 'required' => false, 'constraints' => array(
            new File(array(
                'maxSize' => '500k',
                'mimeTypes' => array(
                    'image/png',
                    'image/jpeg',
                    'image/pjpeg',
                    'image/gif',
                    'image/bmp',
                )
            ))
        )));

Update 2: In my php.ini i set this:

upload_max_filesize = 500k
post_max_size = 500k
anthony
  • 21
  • 4
  • It seems a PHP well-know issue. Take a look at this question: [http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size](http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size) – DonCallisto Jun 21 '15 at 16:21
  • I don't think this solution will stop uploading the file, or i didn't understand. – anthony Jun 21 '15 at 16:38

1 Answers1

0

Try to add the following line to http or in your case server section

client_max_body_size 2M;

Don't forget to adjust your limit. Save file, realod nginx and it should be working.

dwilda
  • 83
  • 2
  • 12