首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lighttpd和cgi python

Lighttpd和cgi python
EN

Stack Overflow用户
提问于 2012-07-31 09:36:42
回答 3查看 8.5K关注 0票数 5

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

lighttpd.conf

代码语言:javascript
复制
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启用/10.cgi.conf

代码语言:javascript
复制
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

代码语言:javascript
复制
print "Content-Type: text/html"
print
print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>"
print "Hello, world!"

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

EN

回答 3

Stack Overflow用户

发布于 2012-07-31 09:40:54

删除“默认”分配

代码语言:javascript
复制
cgi.assign = ( "" => "" )

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

代码语言:javascript
复制
$HTTP["url"] =~ "^/cgi-bin/" {
    cgi.assign = ( ".py" => "/usr/bin/python" )
}

编辑

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

票数 3
EN

Stack Overflow用户

发布于 2013-11-23 22:19:07

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

代码语言:javascript
复制
".py" => "text/x-python",
".pyc" => "application/x-python-code",
".pyo" => "application/x-python-code",
票数 0
EN

Stack Overflow用户

发布于 2018-04-02 20:45:26

我也遇到了这个问题。默认情况下,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数组中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11737183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档