• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php+nginx 上传大文件 502 Bad Gateway

php 搞代码 4年前 (2022-01-25) 61次浏览 已收录 0个评论
文章目录[隐藏]

由于php每天要接收其它服务器post过来的文件
比如我在:192.168.1.147上用下面这条命令
wget http://192.168.1.148/upload.php –post-file=msg.log
这个msg.log 有50M,进行post msg.log这个文件到148服务器的php上存储,进行入库

首先说明:
不要问我怎么不直接复制文件,要用php接收?
我现在讨论的是这个问题,谢谢。

原因:
首次调用出现了:
HTTP request sent, awaiting response… 413 Request Entity Too Large
我按照网上的教程改nginx配置
改为:
client_max_body_size 100m;
满以为解决问题,再次执行报错。
HTTP request sent, awaiting response… 502 Bad Gateway

网上有的说php.ini要配置,但是我的php.ini 配置是64M
max_execution_time 300 300
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 60 60
max_input_vars 1000 1000
memory_limit 128M 128M
open_basedir no value no value
output_buffering 4096 4096
output_handler no value no value
post_max_size 64M 64M
upload_max_filesize 64M 64M

都找了好多,都是说配置php.ini, nginx.conf,还有php-fpm.conf的request_terminate_timeout=0,
最后没用,自己试试就知道了,不多说了,多谢好人!

回复内容:

由于php每天要接收其它服务器post过来的文件
比如我在:192.168.1.147上用下面这条命令
wget http://192.168.1.148/upload.php –post-file=msg.log
这个msg.log 有50M,进行post msg.log这个文件到148服务器的php上存储,进行入库

首先说明:
不要问我怎么不直接复制文件,要用php接收?
我现在讨论的是这个问题,谢谢。

原因:
首次调用出现了:
HTTP request sent, awaiting response… 413 Request Entity Too Large

……本2文来源gaodai.ma#com搞##代!^码@网3

搞代gaodaima码我按照网上的教程改nginx配置
改为:
client_max_body_size 100m;
满以为解决问题,再次执行报错。
HTTP request sent, awaiting response… 502 Bad Gateway

网上有的说php.ini要配置,但是我的php.ini 配置是64M
max_execution_time 300 300
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 60 60
max_input_vars 1000 1000
memory_limit 128M 128M
open_basedir no value no value
output_buffering 4096 4096
output_handler no value no value
post_max_size 64M 64M
upload_max_filesize 64M 64M

都找了好多,都是说配置php.ini, nginx.conf,还有php-fpm.conf的request_terminate_timeout=0,
最后没用,自己试试就知道了,不多说了,多谢好人!

<code>nginx配置:    keepalive_timeout 600;     proxy_send_timeout 600;    client_max_body_size 200M;      fastcgi_connect_timeout 600;    fastcgi_send_timeout 600;    fastcgi_read_timeout 600;    fastcgi_buffer_size 1024k;    fastcgi_buffers 8 1024k;    fastcgi_busy_buffers_size 1024k;    fastcgi_temp_file_write_size 1024k;    proxy_ignore_client_abort on;    tcp_nopush on;    tcp_nodelay on;    client_header_timeout 600;     client_body_timeout 600;     sendfile on;     send_timeout 600;     </code>

php的配置或php-fpm上传大小配置及post大小也需要修改

根据你的实际情况修改上边的配置吧

具体原因不清楚, 不过502错误一般都是PHP那边出了问题
不是没响应,就是响应时间过长,等。
这里已经和nginx没什么关系了

我在Xubuntu 14.04上用测试PHP CLI Server,只配置了下面两条,其他都是默认配置,就能上传90多MB的ZIP包了.

<code>upload_max_filesize=100Mpost_max_size=128M</code>
<code>php -S 127.0.0.1:8080 -t /png/www/example.com/public_html/// chmod 777 /png/www/example.com/public_html/app/yab/static/// http://127.0.0.1:8080/app/yab/upload.php<?phpif(!empty($_FILES)){    $uploaddir = '/png/www/example.com/public_html/app/yab/static/';    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);    echo '<pre class="prettyprint linenums">';    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {        echo "File is valid, and was successfully uploaded.\n";    } else {        echo "Possible file upload attack!\n";    }    echo 'Here is some more debugging info:';    print_r($_FILES);    print "

“; exit();}?> Send this file:

输出:

<code>File is valid, and was successfully uploaded.Here is some more debugging info:Array(    [userfile] => Array        (            [name] => firefox.zip            [type] => application/zip            [tmp_name] => /tmp/phpG1PdtU            [error] => 0            [size] => 93938426        ))</code>

同时本地测试了Nginx + PHP-FPM,Nginx只修改了下面这个配置:

<code>client_max_body_size 128M;</code>

经过我测试,上传文件是可以上传成功的,但是我用wget –post-file 就返回502错误
wget可能有限制大文件上传,
用curl命令搞定:
curl -T “msg.log” “http://192.168.1.148/upload.php&#8221;
谢谢大家 结贴!

nginx_module_upload

你把php的执行时间调大一点,另外上传超时也调大一点。
set_time_limit(),max_input_time之类的。你是不是第一次调完后再上传会等一会儿才报502错?


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php+nginx 上传大文件 502 Bad Gateway

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址