Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

jquery - Apache 403 error (Forbidden) on windows

I'm using Apache and send an ajax request using jQuery from index.html. The get_data.pl is a file on cgi-bin. I got 403 Forbidden error. Anyone would help me and thanks in advance.

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

What I got from the console:

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

It's Windows 7. I'm running with Chrome using administrator account.

After some time, I didn't find ways for the issue yet. I think I should provide more details for experts to reproduce my problem. About my httpd.conf, I changed places based on the original one: Line 193 in:

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

I delete the 2 lines:

Order allow,deny
Allow from all

Line 343 :

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

I changed this section to:

<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>

I placed the .pl file in cgi-bin folder, the index.html in htdocs folder. I tried Windows7, Win2k3 64bit and WIn2k3 32bit. All have forbidden errors. I used Apache's default printenv.pl also.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you are missing permissions to run CGI stuff and you can read about how to enable it in the Apache documentation

In short put something like this in your main config file(https.conf) :

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

Hope it helps you forward.

EDIT
The problem was that the path used to access the script was incorrect. Log file showed Options ExecCGI is off in this directory: C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/get_data.pl" while the get_data.pl file is not in htdocs, but in cgi-bin folder. Changing url: "get_data.pl" in the ajax call to locate the script in cgi-bin solved the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...