最近将网站使用 Nginx 进行反向代理,一切都是正常的,网站能够正常访问。但是,某次上传一个稍大点的文件,抛出如下错误信息:
Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
根据上面的错误信息可以得知,是因为上传的资源太大的原因,导致上传资源失败。
解决办法:
修改 nginx.conf 配置文件,配置允许客户端上传的最大实体大小。配置方式如下:
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;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 允许客户端最大大小为 30M
client_max_body_size 30m;
# gzip
gzip on;
gzip_min_length 1k;
...
}修改配置文件后,使用“nginx -t”先测试配置文件是否正确,如下:
[root@root sbin]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
然后,再使用“nginx -s reload”加载配置文件。