【问题标题】:How can I run Python CGI scripts on my web server?如何在我的 Web 服务器上运行 Python CGI 脚本?
【发布时间】:2011-09-30 11:53:29
【问题描述】:

我想在我的 Web 服务器 (Apache 2.2) 上运行 Python CGI 脚本。当我尝试运行 test.py 文件时,出现以下错误:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /test.py
on this server.</p>
</body></html>

在错误日志中:

[client 127.0.0.1] Options ExecCGI is off in this directory: C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/test.py

那么可能是什么问题?

【问题讨论】:

  • 您无法在浏览器中运行 Python 脚本。您的意思是要在浏览器发出请求时在服务器上运行它们吗?

标签: python apache cgi


【解决方案1】:

试试 mod_python。它是一个嵌入 apache 本身并允许用户在其上运行 python 脚本的 apache 模块

【讨论】:

    【解决方案2】:

    错误日志告诉您,您的 Web 服务器未配置为允许从该目录运行 CGI 脚本。

    请参阅 Apache 常见问题解答中的 How do I enable CGI execution in directories other than the ScriptAlias?。

    【讨论】:

      【解决方案3】:

      将Options ExecCGI添加到python文件所在文件夹的.htaccess文件中。

      除此之外,不要使用 CGI 而是 WSGI 来执行 python 应用程序...

      【讨论】:

        猜你喜欢
        • 2018-01-30
        • 1970-01-01
        • 2017-07-25
        • 2016-12-08
        • 1970-01-01
        • 2012-03-13
        • 2019-08-06
        • 2012-07-27
        相关资源
        最近更新 更多