最近我们的网站服务平台上传 apk(应用程序) 的时候 上传 60M 的 App 的时候 报错 nginx
413 Request Entity Too Large
经过排查修改 nginx 配置
这是最简单的一个做法, 着报错原因是 nginx 不允许上传配置过大的文件, 那么件把 nginx 的上传大小配置调高就好.
1, 打开 nginx 主配置文件 nginx.conf, 找到 http{} 段并修改以下内容:
- http {
- include mime.types;
- default_type application/octet-stream;
- server_names_hash_bucket_size 128;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 100m;
- limit_conn_zone $binary_remote_addr zone=one:32k;
- sendfile on;
- tcp_nopush on;
- keepalive_timeout 60;
- tcp_nodelay on;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 16k;
- gzip_http_version 1.0;
- gzip_comp_level 2;
- gzip_types text/plain application/x-JavaScript text/CSS application/xml;
- gzip_vary on;
- log_format wwwlogs '$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for';
- #include default.conf;
- include vhost/*.conf;
- }
- client_max_body_size 100m;
当中的 100 修改成你需要的允许文件大小.
2, 修改后, 测试 nginx 配置是否正确
重启 nginx
我们的项目是以 PHP 运行的, 这个大小 client_max_body_size 要和 PHP.INI 中的如下值的最大值差不多或者稍大, 这样就不会因为提交数据大小不一致出现错误.
- post_max_size = 100M
- upload_max_filesize = 100M
当中的 100M 修改成你需要的允许文件大小. 把当中的 100M 修改成你第一步设置的大小.
我们修改完 PHP.INI 文件后 重启一下 PHP 然后我们再上传 60M 的 App 时 ok 没问题
来源: http://www.bubuko.com/infodetail-3496872.html