nginx、Apache、IIS服务器解决 413 Request Entity Too Large问题方法汇总

一、nginx服务器

nginx出现这个问题的原因是请求实体太长了。一般出现种情况是Post请求时Body内容Post的数据太大了,
如上传大文件过大、POST数据比较多。

处理方法

在nginx.conf增加 client_max_body_size的相关设置, 这个值默认是1m,可以增加到8m以增加提高文件大小限制;当然可以设置的更大点。

代码如下:
# 在http,server或者location段修改下面的配置:
# set client body size to 8M #
client_max_body_size 8M;

二、Apache服务器

修改下Apache配置文件中的LimitRequestBody配置,如果是虚拟主机,请联系空间商帮助修改。

具体步骤:
在apache环境中上传较大软件的时候,有时候会出现413错误,出现这个错误的原因,是因为apache的配置不当造成的,找到apache的配置文件目录也就是conf目录,和这个目录平行的一个目录叫conf.d打开这个conf.d,里面有一个php.conf
目录内容如下:

代码如下:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

LoadModule php4_module modules/libphp4.so

#
# Cause the PHP interpreter handle files with a .php extension.
#

SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 6550000

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

参与评论