Windows 上的 Apache 403 错误(禁止) [英] Apache 403 error (Forbidden) on windows

查看:63
本文介绍了Windows 上的 Apache 403 错误(禁止)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache 并使用来自 index.html 的 jQuery 发送一个 ajax 请求.get_data.plcgi-bin 上的文件.我收到 403 Forbidden error.任何人都会帮助我并提前致谢.

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

我从控制台得到的:

{"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.

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

过了一段时间,我还没有找到解决这个问题的方法.我想我应该为专家提供更多细节来重现我的问题.关于我的httpd.conf,我在原来的基础上换了个地方:第 193 行:

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>

我删除了两行:

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 文件夹中,将 index.html 放在 htdocs 文件夹中.我尝试了 Windows7、Win2k3 64 位和 WIn2k3 32 位.都有禁止的错误.我也使用了 Apache 的默认 printenv.pl.

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.

推荐答案

我认为您缺少运行 CGI 内容的权限,您可以在 Apache 文档

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

简而言之,在你的主配置文件(https.conf)中加入类似的内容:

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>

希望对你有所帮助.

编辑
问题是用于访问脚本的路径不正确.日志文件显示 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"ajax 调用定位cgi-bin中的脚本解决了这个问题.

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.

这篇关于Windows 上的 Apache 403 错误(禁止)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆