【问题标题】:Apache 403 error (Forbidden) on windowsWindows 上的 Apache 403 错误(禁止)
【发布时间】:2013-10-17 22:27:50
【问题描述】:

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

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

【问题讨论】:

  • 显示您的.htaccess
  • 我在 conf 文件夹中搜索但没有找到 .htaccess。 Apache2.2/manual 文件夹下只有 htaccess.html,我觉得不是你说的配置文件。
  • 对同一目录的其他请求(例如/image.jpg)是否也被禁止或只是.pl文件?
  • 我可以从命令行运行它:cgi-bin>get_data.pl
  • 你安装了mod_perl 吗?

标签: jquery html apache


【解决方案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 中的脚本解决了该问题。

【讨论】:

  • 不,我已经这样做了。我在 httpd.conf 中添加了:AddHandler cgi-script .cgi .pl,路径是 Apache 的默认 cgi-bin。有什么方法可以追踪问题?
  • 重要的是你也有Options +ExecCGI,但我假设你有它。检查错误日志文件?通常在/var/log/apache2 下,但这可能因您的配置而异。
  • 是的,日志文件有帮助。我查看日志文件显示:“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 文件夹中。当我在客户端脚本中调用“url:”get_data.pl“”时,它默认为 htdocs 文件夹,而不是 cgi-bin 文件夹。我该怎么做才能分配给它?
  • 将您的 cgi-bin 文件夹的路径添加到脚本中的 url,或使用 Alias 制作较短的 URL 并引用该 URL。
  • 我认为 cgi-bin 是 Apache 会找到的默认执行根目录,不需要明确引用。我在引用 url 中使用了短名称,现在可以了。谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-29
  • 2011-11-20
  • 1970-01-01
  • 2023-03-24
相关资源
最近更新 更多