最近开发上传文件时,发现图片上传成功,但是上传大一点的视频就直接报错Internal Server Error

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

首先去排查了php.ini的配置参数,发现都满足上传文件的大小:

; php.ini 找到并修改这些行
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 300
max_input_time = 300
memory_limit = 256M

如果是用Apache服务,则在httpd.conf文件后面配置以下参数即可成功解决:


LimitRequestBody 52428800
<IfModule mod_fcgid.c>
FcgidConnectTimeout 20
MaxRequestLen 52428800
</IfModule>

这里我详细解释下对应配置参数的含义:

1. LimitRequestBody 52428800

apache

LimitRequestBody 52428800
  • 作用:限制 HTTP 请求体(request body)的最大大小

  • :52428800 字节 = 50MB

  • 影响范围:所有类型的 POST 请求,包括文件上传

  • 默认值:通常为 0(无限制)或较小的值

2. mod_fcgid 模块配置

apache

<IfModule mod_fcgid.c>
FcgidConnectTimeout 20
MaxRequestLen 52428800
</IfModule>

这是针对 FastCGI 进程的配置:

FcgidConnectTimeout 20
  • 作用:设置连接到 FastCGI 服务器的超时时间

  • :20 秒

  • 含义:如果 Apache 在 20 秒内无法连接到 PHP-FPM(FastCGI 进程),则放弃连接

MaxRequestLen 52428800
  • 作用:限制通过 FastCGI 处理的单个请求的最大长度

  • :52428800 字节 = 50MB

  • 含义:这是 FastCGI 进程能处理的最大请求大小

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐