Nginx报错client intended to send too large body

问题描述:

迁移完服务器后,发现无法上传大文件,查看Nginx日志发现如下报错

[root@localhost ~]# cat /var/log/nginx/error.log
2020/04/16 10:12:40 [error] 14173#14173: *2680 client intended to send too large body: 2045031 bytes, client: 192.168.1.1, server: localhost, request: "POST /index.php?mod=explorer&op=ajax&operation=uploads&container=584 HTTP/1.1", host: "xx.cn", referrer: "http://xx.cn/"

看来是Nginx限制了上传文件的大小。

解决办法:

默认配置完Nginx未配置上传文件大小限制,修改Nginx配置文件,在HTTP{}中添加client_max_body_size字段,设置上传文件大小

[root@localhost ~]# vi /etc/nginx/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  65;

    #gzip  on;

    client_max_body_size 100m;

    include /etc/nginx/conf.d/*.conf;
}
[root@localhost ~]# nginx -s reload

重载Nginx后发现可以正常上传了

添加新评论