[英]Access denied php curl in AWS Elastic Beanstalk
我有一个使用curl来访问外部URL并分析页面内容的PHP应用程序。 我的代码在localhost上运行良好,但是当我将其运行在服务器上时显示错误:
拒绝访问
您无权访问此服务器上的“ 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);
任何想法?
EC2的IP范围经常被阻止对某些站点进行爬网,包括StackOverflow。
该代码对我有用。 您可能需要在AWS实例上打开端口80。 您可以通过编辑与Elastic Beanstalk创建的实例相关联的安全组来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.