lnmp一键包安装,php5.x版本curl访问https出现502 Bad Gateway,http请求成功的

镜面王子
  • 69

问题描述

我使用lnmp1.4版本一键安装包php开发环境,我的系统版本是Ubuntu 18.04.1 LTS.
我只要在php5.x版本发送curl https请求就会出现502错误,http反而可以,但在php7以上版本却不会出现(相同的代码),我本地已经搭建php7.1.17版本+php5.6版本进行测试

问题出现的环境背景及自己尝试过哪些方法

我已经百度很多方法,也尝试过修改php-fpm.conf的request_terminate_timeout,max_children数目调大,可是问题依然存在,然后我又重新编译lnmp1.4版本5.5测试,也是出现我curl https出现502,只有使用php7.0版本才不会,我系统之前有进行升级过了

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

修改php.ini文件

output_buffering = 65535

查看nginx错误日志

[email protected]:/home/wwwlogs$ cat nginx_error.log

2018/09/17 21:12:23 [error] 21050#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /3.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "127.0.0.1"

php-frm配置文件

[email protected]:/usr/local/php/etc# cat php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

php-frm.log错误日志
[17-Sep-2018 21:12:23] WARNING: [pool www] child 20874 exited on signal 11 (SIGSEGV - core dumped) after 8428.414089 seconds from start
[17-Sep-2018 21:12:23] NOTICE: [pool www] child 26731 started

php已经提示安装模块了
[email protected]:/usr/local/php/var/log# /usr/local/php/bin/php -m

[PHP Modules]
bcmath
Core
ctype
curl
date
dom
ereg
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mcrypt
mhash
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend Guard Loader
zip
zlib

[Zend Modules]
Zend Guard Loader

[email protected]:~$ curl -V
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 
[email protected]:~$ 
    

在本地curl

[email protected]:/home/wwwlogs$ curl https://www.sojson.com/api/qqmusic/8446666
curl: (7) Failed to receive SOCKS4 connect request ack.
[email protected]:/home/wwwlogs$ curl http://www.sojson.com/api/qqmusic/8446666
curl: (7) Failed to receive SOCKS4 connect request ack.
[email protected]:/home/wwwlogs$ curl http://www.baidu.com
curl: (7) Failed to receive SOCKS4 connect request ack.
[email protected]:/home/wwwlogs$ curl http://www.sojson.com/api/qqmusic/8446666

3.php测试文件

<?php
$header=array(
"Accept: application/json",
"Content-Type: application/json;charset=utf-8",
);
$get_token_url="https://www.sojson.com/api/qqmusic/8446666";
//$get_token_url="https://www.baidu.com";
$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$get_token_url);

curl_setopt($ch,CURLOPT_HEADER,0);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书

curl_setopt($ch,CURLOPT_RETURNTRANSFER,0 );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);

$res = curl_exec($ch);
$b=curl_error($ch);var_dump($b);die();
var_dump($res);  //有返回值
?>

你期待的结果是什么?实际看到的错误信息又是什么?

我想知道是不是我升级系统的问题,才会导致5.x版本的curl https出现502,我就差没有重装系统了。还有什么办法解决吗?我php7版本却又正常,都是用同一个Nginx版本代理

回复
阅读 2.3k
2 个回答
chenyu977564830
  • 2
新手上路,请多包涵

不是你升级的问题吧,我新装的也是报这个错误

php 502 90% 都是php 连接后 响应时间过短或 单程间的通讯断开了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏