Nginx 上传文件超出大小限制,提示 413 Request Entity Too Large
上传文件时报错 413 Request Entity Too Large,需调整 Nginx client_max_body_size
参数。以下是具体步骤:
1. 修改 Nginx 配置文件
在 Nginx 配置文件(如nginx.conf
或站点配置文件)的http
、server
或location
块中,添加或修改以下参数:
client_max_body_size 100M; # 根据需求调整大小(如100MB)
作用域说明:
全局生效(http 块):
http {
client_max_body_size 100M;
}
单个站点生效(server 块):
server {
listen 80;
server_name example.com;
client_max_body_size 100M;
}
特定路径生效(location 块):
location /upload {
client_max_body_size 100M;
}
2. 重启 Nginx 服务
# 检查配置语法是否正确
nginx -t
# 重新加载配置(不中断服务)
nginx -s reload
# 或直接重启服务
systemctl restart nginx
3. 其他注意事项
传大文件时可能需要调整超时时间:
client_body_timeout 300s;
client_header_timeout 300s;
参考:运维笔记--nginx 上传文件超出默认大小限制,提示:413 Request Entity Too Large、DeepSeek