use*_*404 5 python cgi lighttpd cgi-bin
我在使用Lighttpd和cgi-bin执行python脚本时遇到问题.我在stackoverflow(即Lighttpd和cgi python)和其他网站中发现了类似的问题,但没有一个完全属于我的配置.我可以通过发出"python flash.py"来执行独立的python脚本而不会有任何问题.
可能有助于解决这个问题的关键点是,在运行"apt-get update"和"apt-get upgrade"之前,一切正常.我已经通过搞乱某些文件的权限,以及搞乱配置文件进行了实验,但没有一个帮助.
我已经将所有内容都恢复到运行更新后的状态.这对我来说是一个新的领域,我只是没有足够的教育来找到任何明显的东西.就目前而言,这是我目前的配置.
/etc/lighttpd/lighttpd.conf
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
# "mod_auth",
# "mod_rewrite",
)
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"
server.port = 80
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".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
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"
#auth.backend = "plain"
#auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpwd"
#auth.require = ( "/var/www" =>
#(
#.method. => "basic",
#.realm. => "Authentication required",
#.require. => "user=admin"
#)
#)
Run Code Online (Sandbox Code Playgroud)
等/ lighttpd的/启用的conf-/ 10 cgi.conf
# /usr/share/doc/lighttpd/cgi.txt
server.modules += ( "mod_cgi" )
$HTTP["url"] =~ "^/cgi-bin/" {
cgi.assign = ( ".py" => "/usr/bin/python" )
}
## 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",
#)
Run Code Online (Sandbox Code Playgroud)
/var/www/cgi-bin/flash.py
#Dog Treat Dispenser. Flash Code
import RPIO
import time
import cgi
FLASHER = 22
#ADD CLICKER!
RPIO.setup(FLASHER , RPIO.OUT) #Set FLASHER pin as OUTPUT
for x in range(0, 5): #Flash for 2 seconds
RPIO.output(FLASHER, True)
#ADD CLICKER SUBROUTINE
time.sleep(.500)
RPIO.output(FLASHER, False)
#ADD CLICKER SUBROUTINE
time.sleep(.500)
# reset every channel that has been set up by this program,
# and unexport interrupt gpio interfaces
RPIO.cleanup()
print "Content-Type: text/html"
print "Location: http://10.143.141.164"
print
print "<html><head>"
print "<title>Flash!</title>"
print "</head>"
print "<body>"
print "<h1>Flash!</h1>"
print "</body>"
print "</html>"
Run Code Online (Sandbox Code Playgroud)
经过大量的研究,无处可去,我不知所措.您将提供的任何帮助将不胜感激.如果有什么我错过了,请告诉我,我会尽力把它给你.
谢谢!
这应该有效:
server.modules += ( "mod_cgi" )
cgi.assign = ( ".pl" => "/usr/bin/perl",
".py" => "/usr/bin/python" )
Run Code Online (Sandbox Code Playgroud)
你正在运行什么版本的Python?你升级并安装了python3吗?如果是这样,您还需要安装 python2 并更改/usr/bin/python为/usr/bin/python2
您是否在 Lighttpd 的 mimetypes.conf 文件中设置了 python 的 mimetypes ?它应该看起来像这样:
".py" => "text/x-python",
".pyc" => "application/x-python-code",
".pyo" => "application/x-python-code",
Run Code Online (Sandbox Code Playgroud)
在进行任何更改之前您是否检查过lighttpd的错误日志?日志存储在/var/log/lighttpd/error.log
您遇到的具体问题是什么?当您导航到该目录时,文件是否会尝试下载?如果没有更多信息,很难解决此问题。