对于使用 nginx 的 PHP Web 服务器来说,要增加上传文件大小限制,除了修改 php.ini 文件的 upload_max_filesize 和 post_max_size 参数以外,还需要修改 nginx 的 client_max_body_size 参数,否则上传文件时 nginx 会报错 413 Request Entity Too Large。
在 http、server 或 location 下使用 client_max_body_size size; 即可,默认 size 是 1m,如果设置为 0 代表不检查也就是不限制请求大小。
使用方法如下:
http {
// 其他内容…
client_max_body_size 8M;
// 其他内容…
}Code language: Nginx (nginx)
或
server {
// 其他内容…
client_max_body_size 8M;
// 其他内容…
}Code language: Nginx (nginx)
或
location / {
// 其他内容…
client_max_body_size 8M;
// 其他内容…
}Code language: Nginx (nginx)
可以有不同的作用域,非常灵活。
修改完成后重新加载 nginx 让新配置生效:
sudo nginx -s reloadCode language: Shell Session (shell)
参考资料:
发表回复