文件上传超过 100KB 时挂起,没有 Apache 错误

文件上传超过 100KB 时挂起,没有 Apache 错误

最初发布在 stackoverflow 上,但被删除并移至此处。

Apache 2.4.6 -- PHP 7.0 -- CentOS 7

VM 内存:8GB -- CPU:2 -- 可用硬盘:约 200GB

遇到一个奇怪的问题,当文件上传超过 100KB 时,它就只是停留在那里,什么也不做。

我已多次增加所有相关配置设置,上传大小和帖子最大值最高可达 2GB,但没有任何变化。

小于等于 100KB 的文件可以立即上传,但 200KB 的文件就只能放在那里。


这是我目前正在使用的测试脚本:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('html_errors', 1);
error_reporting(E_ALL);

echo 'file_uploads: ' . ini_get('file_uploads') . '<br>';
echo 'max_execution_time: ' . ini_get('max_execution_time') . '<br>';
echo 'memory_limit: ' . ini_get('memory_limit') . '<br>';
echo 'post_max_size: ' . ini_get('post_max_size') . '<br>';
echo 'upload_max_filesize: ' . ini_get('upload_max_filesize') . '<br>';
echo 'max_input_time: ' . ini_get('max_input_time') . '<br>';


if (isset($_FILES['file'])){
  print_r($_FILES['file']);
}
?>

<!DOCTYPE html>
<html>
<body>

<form action="test.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="file" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

以下是脚本中打印出来的配置设置列表:

file_uploads: 1
max_execution_time: 120
memory_limit: 512M
post_max_size: 100M
upload_max_filesize: 100M
max_input_time: 120

没有什么打印到 httpd 错误日志我尝试上传。

重新启动 httpd 后,这是 error_log:

[Mon Jul 30 10:11:33.843669 2018] [mpm_prefork:notice] [pid 3811] AH00170: caught SIGWINCH, shutting down gracefully
[Mon Jul 30 10:11:35.103671 2018] [core:notice] [pid 3897] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Mon Jul 30 10:11:35.105963 2018] [suexec:notice] [pid 3897] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.8.6.155. Set the 'ServerName' directive globally to suppress this message
[Mon Jul 30 10:11:35.168442 2018] [auth_digest:notice] [pid 3897] AH01757: generating secret for digest authentication ...
[Mon Jul 30 10:11:35.170108 2018] [lbmethod_heartbeat:notice] [pid 3897] AH02282: No slotmem from mod_heartmonitor
[Mon Jul 30 10:11:35.356666 2018] [mpm_prefork:notice] [pid 3897] AH00163: Apache/2.4.6 (CentOS) PHP/7.0.30 configured -- resuming normal operations
[Mon Jul 30 10:11:35.356845 2018] [core:notice] [pid 3897] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

这是尝试上传 200KB 文件后的错误日志,在进程最终崩溃并且我在浏览器中收到错误页面后(我没有收到 500 错误或任何内容,只是“此页面不工作。该页面没有发送任何数据。ERR_EMPTY_RESPONSE”):

[Mon Jul 30 10:11:33.843669 2018] [mpm_prefork:notice] [pid 3811] AH00170: caught SIGWINCH, shutting down gracefully
[Mon Jul 30 10:11:35.103671 2018] [core:notice] [pid 3897] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Mon Jul 30 10:11:35.105963 2018] [suexec:notice] [pid 3897] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.8.6.155. Set the 'ServerName' directive globally to suppress this message
[Mon Jul 30 10:11:35.168442 2018] [auth_digest:notice] [pid 3897] AH01757: generating secret for digest authentication ...
[Mon Jul 30 10:11:35.170108 2018] [lbmethod_heartbeat:notice] [pid 3897] AH02282: No slotmem from mod_heartmonitor
[Mon Jul 30 10:11:35.356666 2018] [mpm_prefork:notice] [pid 3897] AH00163: Apache/2.4.6 (CentOS) PHP/7.0.30 configured -- resuming normal operations
[Mon Jul 30 10:11:35.356845 2018] [core:notice] [pid 3897] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

所以 error_log 中没有添加任何新内容。我不知道这些启动错误是否相关,但我在其他 centos 服务器上遇到了一些此类错误,这些服务器的上传工作正常。


我努力了:

  • 更改 php.ini 和脚本本身的配置设置
  • 删除 php 7.2 并安装 php 7.0
  • 删除 httpd 并重新安装
  • 检查以确保任何 apache conf 文件中都没有 LimitRequestBody
  • 将临时上传目录设置为 /tmp
  • 完全禁用 selinux
  • 重新启动整个机器

这听起来非常类似于:https://stackoverflow.com/questions/6970317/uploading-100kb-zip-files-gives-an-internal-server-error

但是我没有安装mod_fcgid。

这是我的完整 phpinfo:https://files.fm/u/dthwdvna

我现在完全不知所措了。我不知道我是否忽略了一些非常简单的问题,或者这是一个复杂的问题,但除了重新创建整个服务器之外,我别无选择。

这是一个空白的 CentOS 7 最小安装,使用 yum install httpd 等...我在其他服务器上已经多次安装过,从未遇到过此问题。

答案1

从来没有真正弄清楚问题到底是什么,但从使用 IP 地址切换到内部域似乎可以解决问题,所以它是网络上某个地方的问题,但不知道是什么。

相关内容