Directus文件上传错误:Request failed with status code 413

后端开发Directus 106

Directus文件上传错误:Request failed with status code 413

Directus文件上传引起的“Request failed with status code 413”错误是由于文件大小受到服务器配置限制,我在Ubuntu使用Nginx作为反向代理运行Directus项目,因此解决这个问题需要修改Nginxclient_max_body_size参数,由于Ubuntu22Nginx配置文件/etc/nginx/nginx.conf中默认是没有写该参数,所以我们是无法找到该参数的,该参数默认值为1M,因此只要上传超过1M大小的文件都会出现该错误。

Directus413错误都是文件大小受限引起,也会有这样更清晰的报错:

Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)

解决方法

修改/etc/nginx/nginx.conf文件,在http{...}区域中加入参数

client_max_body_size 5M;

这里我写了5M,可根据实际情况修改,修改完毕后先测试nginx语法

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

Post Comment