我试图通过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启用/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!"我真的不明白发生了什么。
发布于 2012-07-31 09:40:54
删除“默认”分配
cgi.assign = ( "" => "" )并且只使用第二个,也许在比赛里面。
$HTTP["url"] =~ "^/cgi-bin/" {
cgi.assign = ( ".py" => "/usr/bin/python" )
}编辑
并确保/usr/bin/python的存在。
发布于 2013-11-23 22:19:07
确保您的Lighttpd的mimetype配置文件中有以下内容:
".py" => "text/x-python",
".pyc" => "application/x-python-code",
".pyo" => "application/x-python-code",发布于 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数组中。
https://stackoverflow.com/questions/11737183
复制相似问题