问题描述在使用 Azure App ServiceLinux PHP 部署 Web 应用时如果上传文件大于1MB就会遇到 HTTP 413Request Entity Too Large 错误。错误截图问题解答一、HTTP 413 错误的本质含义413 Request Entity Too Large 是标准 HTTP 状态码表示客户端提交的请求体Request Body大小超过了服务器当前允许的最大限制。在 Azure App ServiceLinux环境中这个错误并不一定来自前端网关(Frontend)而更常见的来源是 App Service 容器内部的 Web Server如 Nginx或运行时如 PHP。二、Nginx 默认的 client_max_body_size 限制在 Linux App Service 中平台内置 Nginx 作为 Web Server。Nginx 会在请求到达应用之前对请求体大小进行校验。当上传文件大小超过 Nginx 允许的最大值时(Nginx 对上传请求体大小的默认限制为 1 MB需要通过 client_max_body_size 参数修改大小)Nginx 会直接返回 413, 请求不会进入 PHP如果未显式配置该值通常较小不适合文件上传场景。通过自定义 Nginx 配置将其调整为更大的值例如 20MB即可解除这一层限制。解决方案修改 App Service默认Nginx的client_max_body_size参数第一步把App Service默认的Nginx配置复制到home/site/wwwroot目录中进入kudu选择SSH到Application, 执行cp命令cp /etc/nginx/sites-available/default /home/site/wwwroot/default操作截图第二步添加client_max_body_size参数并设置为20M在Kudu页面的File Manager中进入home/site/wwwroot目录中选择default文件直接UI上添加client_max_body_size 20M;后保存。操作截图第三步覆盖nginx default配置并重启因修改了默认的nginx配置为了使得配置生效需要用新的配置文件覆盖默认配置并重启nginx服务。使用如下命令cp /home/site/wwwroot/default /etc/nginx/sites-available/default service nginx reload此命令将默认 NGINX 配置文件替换为存储库根目录中命名 default 的文件并重新启动 NGINX。操作截图结论完成以上三步之后刷新php应用的上传页面再次上传小于20MB的文件成功。参考资料Azure App ServiceLinux自定义 Nginx 配置https://learn.microsoft.com/azure/app-service/configure-language-php?pivotsplatform-linux#change-the-site-rootNginx 官方文档client_max_body_sizehttps://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_sizeSyntax: client_max_body_size size;Default: client_max_body_size 1m;Context: http, server, locationSets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.当在复杂的环境中面临问题格物之道需浊而静之徐清安以动之徐生。 云中恰是如此!