七牛上传文件服务器显示502,如何解决?

不言
Release: 2023-02-28 11:14:01
Original
3422 people have browsed it

服务器环境是nginx+php-fpm
用七牛的php-sdk写了个上传文件的demo,本地运行正常,上传到服务器测试出现以下结果:

1.服务器终端下运行命令:`php demo.php`,结果正常,文件成功上传。
2.用浏览器访问:`http://xxx.com/demo.php`,然后会经过长时间的等待返回502错误,文件上传失败。

到网上找了一些解决nginx 502错误的方法,但貌似都没有生效,求指教该如何解决这个问题。

附上demo.php代码:

<?php
set_time_limit(0);

require_once  &#39;vendor/autoload.php&#39;;

use Qiniu\Storage\UploadManager;
use Qiniu\Auth;

// 用于签名的公钥和私钥
 $accessKey = &#39;***&#39;;
 $secretKey = &#39;***&#39;;

 // 初始化签权对象
 $auth = new Auth($accessKey, $secretKey);

 $bucket = &#39;blog&#39;;

 // 生成上传Token
 $token = $auth->uploadToken($bucket);

 // 构建 UploadManager 对象
 $uploadMgr = new UploadManager();

$data = file_get_contents(&#39;11.jpg&#39;);
 $rt = $uploadMgr->put($token,substr(md5(time()),0,10).&#39;.jpg&#39;,$data);

 print_r($rt);
Copy after login
Copy after login

回复内容:

服务器环境是nginx+php-fpm
用七牛的php-sdk写了个上传文件的demo,本地运行正常,上传到服务器测试出现以下结果:

1.服务器终端下运行命令:`php demo.php`,结果正常,文件成功上传。
2.用浏览器访问:`http://xxx.com/demo.php`,然后会经过长时间的等待返回502错误,文件上传失败。

到网上找了一些解决nginx 502错误的方法,但貌似都没有生效,求指教该如何解决这个问题。

附上demo.php代码:

<?php
set_time_limit(0);

require_once  &#39;vendor/autoload.php&#39;;

use Qiniu\Storage\UploadManager;
use Qiniu\Auth;

// 用于签名的公钥和私钥
 $accessKey = &#39;***&#39;;
 $secretKey = &#39;***&#39;;

 // 初始化签权对象
 $auth = new Auth($accessKey, $secretKey);

 $bucket = &#39;blog&#39;;

 // 生成上传Token
 $token = $auth->uploadToken($bucket);

 // 构建 UploadManager 对象
 $uploadMgr = new UploadManager();

$data = file_get_contents(&#39;11.jpg&#39;);
 $rt = $uploadMgr->put($token,substr(md5(time()),0,10).&#39;.jpg&#39;,$data);

 print_r($rt);
Copy after login
Copy after login

现在还存在这个问题?你服务器是否不稳定呢?可能需要购买比较稳定的服务器,


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template