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

王林
Release: 2020-12-10 16:07:44
forward
5085 people have browsed it

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
Copy after login

(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.
Copy after login

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;
	....
	}
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!