我在虚拟机的Ubuntu 18LTS上使用lighttpd 1.4.45。我已经启用了 cgi 模块,将分配设置为 python(我也尝试了通常的 ^/cgi-bin/(,并将".py"添加到静态文件排除列表中。
我的问题是,尽管看起来正确地将python配置为我的CGI解释器,但lighttpd似乎仍然将.py文件称为静态文件。在任何目录(包括 cgi-bin(中加载 python 文件都会导致提示下载该文件。Firefox用于测试。
我的 lighttpd.conf:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_cgi",
)
server.document-root = "/home/william/Desktop/Space.io/"
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"
server.port = 80
index-file.names = ( "index.py", "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".py", ".php", ".pl", ".fcgi" )
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
我的 10-cgi.conf:
# /usr/share/doc/lighttpd/cgi.txt
server.modules += ( "mod_cgi" )
cgi.assign = ( ".pl" => "/usr/bin/perl",
".py" => "/usr/bin/python" )
#$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",
#)
为什么会这样?如何正确配置 lighttpd 来执行 python 文件?
交叉发布并在 https://redmine.lighttpd.net/boards/2/topics/8074 回答
LightTPD 工作正常。 您的浏览器提示您保存文件,因为来自 python 代码的响应不包含指示内容类型的 Content-Type 响应标头(例如文本/html 或文本/纯文本(