Home>Article>Operation and Maintenance> nginx fails to upload files and prompts that the uploaded file is too large. How to solve the problem?

nginx fails to upload files and prompts that the uploaded file is too large. How to solve the problem?

王林
王林 forward
2020-12-10 16:07:44 5079browse

nginx fails to upload files and prompts that the uploaded file is too large. How to solve the problem?

Problem description:

Failed to upload the file, the file size is about 4M. The upload program is Java and is written to Fastdfs through nginx reverse proxy, but it always fails. Check the nginx error log and the following content is displayed:

client intended to send too large body: 4134591 bytes

(Related recommendations:nginx tutorial)

Analysis:

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

The official document is as follows:

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 document, you can add configuration, client_max_body_size size, in the http, server, location and other configuration blocks in the nginx configuration file ;To adjust the body size of files allowed to be uploaded by clients. Set to 0, indicating no limit.

Code example:

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

The above is the detailed content of nginx fails to upload files and prompts that the uploaded file is too large. How to solve the problem?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete