【问题标题】:Access denied php curl in AWS Elastic BeanstalkAWS Elastic Beanstalk 中的访问被拒绝 php curl
【发布时间】:2015-02-04 18:36:59
【问题描述】:

我有一个 PHP 应用程序,它使用 curl 访问外部 url 并分析页面内容。我的代码在本地主机上运行良好,但是当我把它放在服务器上运行时显示错误:

访问被拒绝

您无权在此访问“http://www.example.com” 服务器。参考#18.aec67bc8.1417892829.438558f

我的代码

$cookie_file = '';
$post_fields = 'id=1';
$agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt($ch, CURLOPT_USERAGENT,$agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);     
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);    

$output = curl_exec($ch);

有什么想法吗?

【问题讨论】:

  • 知道哪个网站阻止了您会很有帮助。基本上该站点拒绝了您的 HTTP 请求,可能是 IP 或假用户代理(不能来自 EC2)。

标签: php curl amazon-web-services amazon-elastic-beanstalk


【解决方案1】:

EC2 的 IP 范围经常被阻止抓取某些网站,包括 StackOverflow。

【讨论】:

  • 是的,这是我的问题,做了一些测试和其他 URL 工作,有没有办法更改或隐藏我的目标服务器的 IP 不会阻止我?
  • @LucianoMarqueto 如果您有合法的用例,请联系该网站并申请豁免。
【解决方案2】:

代码对我有用。您可能需要在 AWS 实例上打开端口 80。您可以通过编辑与 Elastic Beanstalk 创建的实例关联的安全组来做到这一点。

【讨论】:

    猜你喜欢
    • 2012-08-25
    • 2013-04-28
    • 2013-04-09
    • 2021-11-28
    • 2015-11-12
    • 2020-11-03
    • 1970-01-01
    • 2017-09-01
    • 2021-07-25
    相关资源
    最近更新 更多