Nginx failed to upload a file, it prompts that the uploaded file is too large, how to solve it


Problem description:

Failed to upload the file, the file size is about 4M. The upload program is Java, and it is written to Fastdfs through the nginx reverse proxy, but it keeps failing. Check the nginx error log, and the prompt is as follows:

1

client intended to send too large body: 4134591 bytes

(Related recommendation: nginx tutorial)

Analysis:

According to the error The message prompts that the body sent by the client is too large. The default client body size of nginx is 1M.

The official document is as follows:

1

2

3

4

Syntax: client_max_body_size size;

Default: client_max_body_size 1m;

Context: http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

Solution:

According to the official documentation, you can add configuration to the http, server, location and other configuration blocks in the nginx configuration file, client_max_body_size size; To adjust the body size of the file uploaded by the client. Set to 0, which means unlimited.

Code example:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

http {

    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;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;

     

    client_max_body_size 100m;

    ....

    }

Guess you like

Origin blog.csdn.net/hdl17822307857/article/details/112915313