【问题标题】:Lighttpd and cgi pythonLighttpd 和 cgi python
【发布时间】:2012-07-31 09:36:42
【问题描述】:

我正在尝试通过 lighttpd 执行一些 python 脚本,但是当我尝试运行它时,我只得到一个空白文件,要求我下载。

lighttpd.conf

server.modules  = (
            "mod_access",
            "mod_alias",
            "mod_accesslog",
            "mod_compress",
            "mod_rewrite"
)

server.port                 = 8080
server.bind                 = "127.0.0.1"
server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"



index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm",
                               " index.lighttpd.html" )


url.access-deny             = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".py" )

dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

/etc/lighttpd/conf-enabled/10.cgi.conf

server.modules += ( "mod_cgi" )

$HTTP["url"] =~ "^/cgi-bin/" {
    cgi.assign = ( "" => "" )
}

## Warning this represents a security risk, as it allow to execute any file
## with a .pl/.py even outside of /usr/lib/cgi-bin.
#
cgi.assign      = (
#   ".pl"  => "/usr/bin/perl",
    ".py"  => "/usr/bin/python"
)

/var/www/cgi-bin/hellopy.py

print "Content-Type: text/html"
print
print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>"
print "Hello, world!"

我真的不明白发生了什么。

【问题讨论】:

  • 不需要完整的 lighttpd.conf。
  • 对不起,但为了防止任何帮手让我发布它:D
  • 你试过在文件上设置执行位吗?

标签: python lighttpd


【解决方案1】:

删除“默认”分配

cgi.assign = ( "" => "" )

并且只使用第二个,也许在比赛中。

$HTTP["url"] =~ "^/cgi-bin/" {
    cgi.assign = ( ".py" => "/usr/bin/python" )
}

编辑

并确保/usr/bin/python 存在。

【讨论】:

  • 不,已经尝试过,(并再次尝试)=/,/usr/bin/python 存在。但是谢谢:)
【解决方案2】:

确保您的 Lighttpd 的 mimetypes 配置文件中有以下内容:

".py" => "text/x-python",
".pyc" => "application/x-python-code",
".pyo" => "application/x-python-code",

【讨论】:

    【解决方案3】:

    我也遇到了这个问题。默认情况下,cgi 模块被禁用。要启用,请尝试运行sudo lighttpd-enable-mod cgi,然后运行/etc/init.d/lighttpd force-reload,然后重试。另请记住,如果您设置了cgi.execute-x-only = enable,则需要使您的 cgi 脚本可执行,例如chmod a+x index.py.

    如果这仍然不起作用,您可以尝试将 "mod_cgi" 添加到您的 server.modules 数组中。

    【讨论】:

      猜你喜欢
      • 2013-11-01
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多