php 413 请求实体太大 - 文件上传问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24306335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
413 Request Entity Too Large - File Upload Issue
提问by Raju Vishwas
I am trying to upload 30MB file on my server and its not working.
我正在尝试在我的服务器上上传 30MB 的文件,但它不起作用。
When I upload 30MB file, the page loads "Page Not Found"
When I upload a 3MB file, I receive "413 Request Entity Too Large" with nginx/0.6.32
当我上传 30MB 文件时,页面加载“找不到页面”
当我上传 3MB 文件时,我收到“ 413 Request Entity Too Large”和 nginx/0.6.32
I am trying to find nginx so I can increase "client_max_body_size" but I am unable to find nginx installed on my server. I even tried running:
我试图找到 nginx 以便我可以增加“ client_max_body_size”,但我无法在我的服务器上找到安装的 nginx。我什至尝试运行:
vi /etc/nginx/nginx.conf
or
或者
vi /usr/local/nginx/conf/nginx.conf
to check if the config file exists, but I couldnt find it on my server.
检查配置文件是否存在,但我在我的服务器上找不到它。
Is there anyway to resolve this issue? Or do I have to installed nginx on my server.
有没有办法解决这个问题?或者我必须在我的服务器上安装 nginx。
EDIT:
编辑:
I have made all necessary changes in my php.ini files,
我已经在我的 php.ini 文件中进行了所有必要的更改,
post_max_size 128M
upload_max_filesize 100M
memory_limit 256M
Thanks, Raju
谢谢,拉朱
回答by Dieter
Source: http://www.cyberciti.biz/faq/linux-unix-bsd-nginx-413-request-entity-too-large/
来源:http: //www.cyberciti.biz/faq/linux-unix-bsd-nginx-413-request-entity-too-large/
Edit the conf file of nginx:
编辑nginx的conf文件:
nano /etc/nginx/nginx.conf
Add a line in the http section:
在 http 部分添加一行:
http {
client_max_body_size 100M;
}
Doen't use MB it will not work, only the M!
不使用MB是不行的,只有M!
Also do not forget to restart nginx
另外不要忘记重启nginx
systemctl restart nginx
回答by Arun
-in php.ini (inside /etc/php.ini)
-in php.ini (在 /etc/php.ini 里面)
max_input_time = 24000
max_execution_time = 24000
upload_max_filesize = 12000M
post_max_size = 24000M
memory_limit = 12000M
-in nginx.conf(inside /opt/nginx/conf)
-in nginx.conf(在/opt/nginx/conf里面)
client_max_body_size 24000M
Its working for my case
它适用于我的情况
回答by Sanaulla
First edit the Nginx configuration file (nginx.conf
)
首先编辑Nginx配置文件( nginx.conf
)
Location: sudo nano /etc/nginx/nginx.conf
地点: sudo nano /etc/nginx/nginx.conf
Add following codes:
添加以下代码:
http {
client_max_body_size 100M;
}
Then Add the following lines in PHP configuration file(php.ini
)
然后在PHP配置文件中添加以下几行( php.ini
)
Location: sudo gedit /etc/php5/fpm/php.ini
地点: sudo gedit /etc/php5/fpm/php.ini
Add following codes:
添加以下代码:
memory_limit = 128M
post_max_size = 20M
upload_max_filesize = 10M
回答by Cagdas
Please enter domain nginx file :
请输入域 nginx 文件:
nano /etc/nginx/sites-available/domain.set
Add to file this code
将此代码添加到文件中
client_max_body_size 24000M;
If you get error use this command
如果出现错误,请使用此命令
nginx -t
回答by Samson 'Melah' Nyabanga
Assuming that you made the necessary changes in your php.ini files:
假设您在 php.ini 文件中进行了必要的更改:
You can resolve the issue by adding the following line in your nginx.conf file found in the following path:
您可以通过在位于以下路径的 nginx.conf 文件中添加以下行来解决该问题:
/etc/nginx/nginx.conf
then edit the file using vim text editor as follows:
然后使用 vim 文本编辑器编辑文件,如下所示:
vi /etc/nginx/nginx.conf
and add client_max_body_size with a large enough value, for example:
并添加具有足够大值的 client_max_body_size,例如:
client_max_body_size 20MB;
After that make sure you save using :xi
or :wq
之后,请确保您保存使用:xi
或:wq
And then restart your nginx.
然后重启你的nginx。
That's it.
就是这样。
Worked for me, hope this helps.
为我工作,希望这有帮助。
回答by Evan
I add the changes directly to my virtualhost instead the global config of nginx, like this:
我将更改直接添加到我的虚拟主机而不是 nginx 的全局配置,如下所示:
server {
client_max_body_size 100M;
...
}
And then I change the params in php.ini, like the comments above:
然后我更改了 php.ini 中的参数,就像上面的评论一样:
max_input_time = 24000
max_execution_time = 24000
upload_max_filesize = 12000M
post_max_size = 24000M
memory_limit = 12000M
and what you can not forget is to restart nginx and php-fpm, in centos 7 is like this:
而你不能忘记的是重启nginx和php-fpm,在centos 7中是这样的:
systemctl restart nginx
systemctl restart php-fpm
回答by Nafas Sait
I got the upload working with above changes. But when I made the changes I started getting 404 response in file upload which lead me to do further debugging and figured out its a permission issue by checking nginx error.log
我通过上述更改进行了上传。但是当我进行更改时,我开始在文件上传中收到 404 响应,这导致我进行进一步的调试并通过检查 nginx error.log 找出它的权限问题
Solution:
解决方案:
Check the current user and group ownership on /var/lib/nginx.
检查 /var/lib/nginx 上的当前用户和组所有权。
$ ls -ld /var/lib/nginx
drwx------. 3 nginx nginx 17 Oct 5 19:31 /var/lib/nginx
drwx------. 3 nginx nginx 17 Oct 5 19:31 /var/lib/nginx
This tells that a possibly non-existent user and group named nginx owns this folder. This is preventing file uploading.
这表明可能不存在的名为 nginx 的用户和组拥有此文件夹。这是阻止文件上传。
In my case, the username mentioned in "/etc/nginx/nginx.conf" was
就我而言,“/etc/nginx/nginx.conf”中提到的用户名是
user vagrant;
Change the folder ownership to the user defined in nginx.conf in this case vagrant.
在这种情况下,将文件夹所有权更改为 nginx.conf 中定义的用户。
$ sudo chown -Rf vagrant:vagrant /var/lib/nginx
Verify that it actually changed.
验证它确实发生了变化。
$ ls -ld /var/lib/nginx
drwx------. 3 vagrant vagrant 17 Oct 5 19:31 /var/lib/nginx
Reload nginx and php-fpm for safer sade.
重新加载 nginx 和 php-fpm 以确保安全。
$ sudo service nginx reload
$ sudo service php-fpm reload
The permission denied error should now go away. Check the error.log (based on nginx.conf error_log location).
权限被拒绝错误现在应该消失了。检查 error.log(基于 nginx.conf error_log 位置)。
$ sudo nano /path/to/nginx/error.log
回答by Tai Ho
Open file/etc/nginx/nginx.conf
Add or change client_max_body_size 0;
打开文件/etc/nginx/nginx.conf
添加或更改client_max_body_size 0;
回答by Saqib Ashraf
Use:
用:
php -i
command or add:
命令或添加:
phpinfo();
to get the location of configuration file.
获取配置文件的位置。
Update these variables according to your need and server
根据您的需要和服务器更新这些变量
max_input_time = 24000
max_execution_time = 24000
upload_max_filesize = 12000M
post_max_size = 24000M
memory_limit = 12000M
On Linux you will need to restart nginx / apache and phpfpm service so the new ini settings are loaded. On xampp, ammps you can restart these from control panel that comes with such applications.
在 Linux 上,您需要重新启动 nginx / apache 和 phpfpm 服务,以便加载新的 ini 设置。在 xampp、ampps 上,您可以从此类应用程序附带的控制面板中重新启动它们。