2012-07-31 81 views
3

我想通過lighttpd執行一些python腳本,但是當我嘗試運行它時,我只得到一個空白文件,我被要求下載。Lighttpd和CGI蟒蛇

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!" 

我真的不明白髮生了什麼事。

+0

完整lighttpd.conf是沒有必要的。 – 2012-07-31 09:43:49

+2

對不起,但它是爲了防止任何幫助者要求我發佈它:D – Semtex 2012-07-31 12:20:27

+0

您是否嘗試過在該文件上設置執行位? – 2012-12-05 17:21:53

回答

2

刪除「默認」分配

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

,並且只使用第二個,或許在比賽中。

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

編輯

,並確保/usr/bin/python存在。

+0

不,已經嘗試過了(再試一次)= /,'/ usr/bin/python'存在。但謝謝:) – Semtex 2012-07-31 12:15:12

0

確保您已在Lighttpd的的MIME類型的配置文件如下:

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