2013-10-10 107 views
1

我使用Apache並使用jQuery從index.html發送ajax請求。 get_data.plcgi-bin上的文件。我得到了403 Forbidden error。任何人都會幫助我,並提前感謝。窗口上的Apache 403錯誤(禁止)

$.ajax({ 
    async : true, 
    type: "GET", 
    url: "get_data.pl"  
}).done(function(msg){ 
    alert("Data Saved: " + msg); 
}).fail(function(xmlHttpRequest,statusText,errorThrown) { 
    console.log(JSON.stringify(xmlHttpRequest)); 
    console.log(statusText); 
    console.log(errorThrown);  
}); 

我從控制檯得到了什麼:

{"readyState":4,"responseText":"<!DOCTYPE ...<title>403 Forbidden</title>... 
<p>You don't have permission to access /get_data.pl\non this server.</p>\n</body> 
</html>\n","status":403,"statusText":"Forbidden"} 

這是Windows 7中我使用的是管理員帳戶與Chrome瀏覽器上運行。

過了一段時間,我還沒有找到解決問題的方法。我想我應該爲專家提供更多的細節來重現我的問題。 關於我的httpd.conf中,我改變了在原有基礎上一個地方:193 線中:

<Directory /> 
    Options FollowSymLinks 
    AllowOverride None 
    Order allow,deny 
    Allow from all 
</Directory> 

我刪除了2行:

Order allow,deny 
Allow from all 

行343:

<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin"> 
     AllowOverride None 
     Options None 
     Order allow,deny 
     Allow from all 
</Directory> 

我將此部分更改爲:

<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin"> 
AllowOverride None 
    Options +ExecCGI 
    AddHandler cgi-script .cgi .pl 
    Allow from all 
</Directory> 

我將.pl文件放在cgi-bin文件夾中,htdocs文件夾中的index.html。 我試過Windows7,Win2k3 64bit和WIn2k3 32bit。所有都有禁止的錯誤。我也使用了Apache的默認printenv.pl。

+1

顯示您的'.htaccess'。 – haim770

+0

我在conf文件夾中搜索,但沒有找到.htaccess。 Apache2.2/manual文件夾下只有htaccess.html,我不認爲它是你提到的配置文件。 –

+0

對同一目錄的其他請求(例如'/ image.jpg')是否也被禁止或僅僅是'.pl'文件? – haim770

回答

1

我想你沒有權限運行CGI的東西,你可以閱讀有關如何啓用它在Apache documentation

在賣出看跌期權這樣的事情在你的主配置文件(https.conf):

<Directory /path/to/cgi-bin/> 
    Options +ExecCGI 
    AddHandler cgi-script .pl 
</Directory> 

希望它可以幫助你前進。

編輯
問題是用於訪問腳本的路徑不正確。日誌文件顯示Options ExecCGI is off in this directory: C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/get_data.pl"get_data.pl文件不在htdocs中,但在cgi-bin文件夾中。在ajax調用url: "get_data.pl"調用找到cgi-bin中的腳本解決了這個問題。

+0

不,我已經完成了。我在我的httpd.conf中添加了:AddHandler cgi-script .cgi .pl,路徑是Apache的默認cgi-bin。任何方式來追蹤這個問題? –

+0

Importatnt你也有'選項+ ExecCGI',但我認爲你有它。檢查錯誤日誌文件?通常在'/ var/log/apache2'下,但是這可能在你的配置中有所不同。 – Qben

+0

是的,日誌文件有幫助。我檢查了日誌文件顯示:「Options ExecCGI關閉在這個目錄中:C:/ Program Files(x86)/ Apache Software Foundation/Apache2.2/htdocs/get_data.pl」實際上,get_data.pl文件不在htdocs文件夾,但在cgi-bin文件夾中。當我在客戶端腳本中調用「url:」get_data.pl「」時,它默認爲htdocs文件夾,而不是cgi-bin文件夾。我該如何分配給它? –