简体   繁体   English

在AWS Elastic Beanstalk中访问被拒绝的php curl

[英]Access denied php curl in AWS Elastic Beanstalk

I have a PHP application that uses curl to access an external url and analyze the content of the page. 我有一个使用curl来访问外部URL并分析页面内容的PHP应用程序。 My code worked perfectly on localhost but when I put it to run on the server displays the error: 我的代码在localhost上运行良好,但是当我将其运行在服务器上时显示错误:

Access Denied 拒绝访问

You don't have permission to access " http://www.example.com " on this server. 您无权访问此服务器上的“ http://www.example.com ”。 Reference #18.aec67bc8.1417892829.438558f 参考#18.aec67bc8.1417892829.438558f

My code 我的密码

$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);

Any idea? 任何想法?

EC2的IP范围经常被阻止对某些站点进行爬网,包括StackOverflow。

The code works for me. 该代码对我有用。 You probably need to open port 80 on your AWS instance. 您可能需要在AWS实例上打开端口80。 You can do that by editing the Security Group associated with the instance created by Elastic Beanstalk. 您可以通过编辑与Elastic Beanstalk创建的实例相关联的安全组来实现。

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

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