2014-12-06 21 views
0

我有一個PHP應用程序,它使用curl訪問外部URL並分析頁面的內容。我的代碼工作完全在本地主機上,但是當我把它在服務器上顯示運行錯誤:在AWS中拒絕訪問php curl Elastic Beanstalk

Access Denied

You don't have permission to access " http://www.example.com " on this server. Reference #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); 

任何想法?

+0

這將有助於知道哪個網站阻止了你。基本上,該網站已拒絕您的HTTP請求,可能是IP或僞造的用戶代理(不能來自EC2)。 – Tal 2014-12-07 06:04:00

回答

1

EC2的IP範圍經常被阻止爬行一些網站,包括StackOverflow。

+0

是的,這是我的問題做了一些測試和其他URL的作品,有沒有辦法改變或隱藏我的IP爲目標服務器不阻止我? – 2014-12-07 23:55:49

+0

@LucianoMarqueto如果您有合法用例,請聯繫本網站並要求豁免。 – ceejayoz 2014-12-08 01:29:03

0

該代碼適用於我。您可能需要在AWS實例上打開端口80。您可以通過編輯與由Elastic Beanstalk創建的實例關聯的安全組來完成此操作。