简体   繁体   English

NGINX 502 bad gateway 通过 CURL 运行时出错

[英]NGINX 502 bad gateway Error when running thru CURL

I am using the following code to run curl.But for one url, I am getting 502 Bad Gateway error.我正在使用以下代码运行 curl。但是对于一个 url,我收到 502 Bad Gateway 错误。

   <?php
//$proxy = '127.0.0.1:80';
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '<requesturl>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_SSL_VERIFYHOST=>false,
//CURLOPT_PROXY=>$proxy,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Cookie: PHPSESSID=e03338f51c56ada6870d530080127581'
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);
    print_r($response);
    print_r($err);
curl_close($curl);



?>

I have removed https and put http and checked but for that also not working.我已经删除了 https 并放置了 http 并进行了检查,但这也不起作用。

My PHP version is 5.6.我的 PHP 版本是 5.6。

Thanks, Rekha谢谢,雷哈

I have found the answer.I have added user agent and it worked fine.我找到了答案。我添加了用户代理,效果很好。

curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

For dynamically get user agent in php,对于在 php 中动态获取用户代理,

$userAgent = $_SERVER['HTTP_USER_AGENT'];

This will help someone.这将帮助某人。

Thanks, Rekha谢谢,雷哈

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM