skip to Main Content

Good morning,
I have a problem for some time that i don’t know how to solve.

From a Spring application i am trying to upload a file to the server.
Everything is fine, except when the file is larger than 200MB. There, the application returns a 413 .. sometimes simply
connection timeout..
The server is Centos 7 and there is Nginx underneath.
I tried running the client_max_body_size but it doesn’t matter.
Anyone know what the problem might be?

These are my configuration’s files

application.properties:

spring.servlet.multipart.maxFileSize=-1
spring.servlet.multipart.maxRequestSize=-1
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1

/etc/nginx/nginx.conf:

http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';

      access_log  /var/log/nginx/access.log  main;
      sendfile        on;
      #tcp_nopush     on;

      keepalive_timeout  3000;

      gzip  on;

      include /etc/nginx/conf.d/*.conf;

      client_max_body_size 500M;

      server{

           client_max_body_size 0;

           location /upload {

                   client_max_body_size  500M;

                   return 201 $request_body_file;
          }

          location / {

                   client_max_body_size 500M;
          }
      }

  }

/etc/php.ini:

 max_input_time = 24000
 max_execution_time = 24000
 upload_max_filesize = 500M
 post_max_size = 500M
 memory_limit = 12000

2

Answers


  1. Chosen as BEST ANSWER

    Already done. I put client_max_body_size everywhere, but it has no effect

    /etc/nginx:

      drwxr-xr-x 2 root root 4096 Oct 26 16:05 conf.d
      -rw-r--r-- 1 root root 1007 Oct 29  2020 fastcgi_params
      -rw-r--r-- 1 root root   44 Feb  9  2021 htpasswd
      -rw-r--r-- 1 root root 2837 Oct 29  2020 koi-utf
      -rw-r--r-- 1 root root 2223 Oct 29  2020 koi-win
      -rw-r--r-- 1 root root 5231 Oct 29  2020 mime.types
      lrwxrwxrwx 1 root root   29 Feb  9  2021 modules -> ../../usr/lib64/nginx/modules
      -rw-r--r-- 1 root root  973 Oct 27 09:09 nginx.conf
      -rw-r--r-- 1 root root  636 Oct 29  2020 scgi_params
      drwxr-xr-x 2 root root 4096 Oct 27 11:12 sites-avaiable
      -rw-r--r-- 1 root root  664 Oct 29  2020 uwsgi_params
      -rw-r--r-- 1 root root 3610 Oct 29  2020 win-utf
      -rw-r--r-- 1 root root 1010 Feb  9  2021 zeppelin_proxy.conf
      -rw-r--r-- 1 root root  910 Jun 30 12:53 zeppelin_proxy_local.conf
    

    nginx.conf:

     user  nginx;
      worker_processes  1;
    
      error_log  /var/log/nginx/error.log warn;
      pid        /var/run/nginx.pid;
    
    
      events {
          worker_connections  1024;
      }
    
    
      http {
          include       /etc/nginx/mime.types;
          default_type  application/octet-stream;
          log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
    
          access_log  /var/log/nginx/access.log  main;
          sendfile        on;
          #tcp_nopush     on;
    
          keepalive_timeout  300000;
    
          gzip  on;
    
          include /etc/nginx/conf.d/*.conf;
    
          client_max_body_size 5000M;
    
          proxy_read_timeout 3000;
          proxy_connect_timeout 3000;
          proxy_send_timeout 3000;
    
          server{
    
               client_max_body_size 5000M;
    
               location /upload {
    
                       client_max_body_size  5000M;
    
                       return 201 $request_body_file;
              }
    
              location / { 
                client_max_body_size 5000M;
              }
    
            proxy_read_timeout 3000;
            proxy_connect_timeout 3000;
            proxy_send_timeout 3000;
          }
      }
    

    Service:

    systemctl restart nginx and systemctl reload nginx

    Upload file greater a 200MB and: enter image description here


  2. You need to change the Nginx server settings by modifying the file nginx.conf. Look for the directive client_max_body_size in this file and change the value (in megabytes) to the maximum file size you prefer. Save the file, and reload Nginx to see the change.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search