2013-10-23 80 views
5

Lighttpdとcgi-bin内で実行するpythonスクリプトの取得に問題があります。 stackoverflow(つまりLighttpd and cgi python)と他のウェブサイトで同様の問題が見つかりましたが、私の設定に完全に関係しているものはありません。 "python flash.py"を発行してスタンドアロンのPythonスクリプトを実行しても問題はありません。LighttpdとCGIでPythonスクリプトを実行

これを解決するためのポイントは、私が "apt-get update"と "apt-get upgrade"を実行する前にすべてがうまくいたということです。私は、特定のファイルに対するパーミッションを混乱させて、設定ファイルを混乱させて実験しましたが、どれも役に立たなかった。

私はそれ以来、更新を実行した直後の状態に戻しました。これは私のための新しい領域です。私は何かを明らかにするのに十分な教育を受けていません。現状では、私の現在の構成があります。

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" 
#) 
#) 

など/ lighttpdの/ confに対応/ 10-cgi.conf /etc/lighttpd/lighttpd.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", 
#) 

の/ var/www /のCGI-binに/フラッシュ。 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>" 

1リットルの研究を行い、どこにもいないと、私は迷っています。あなたが提供できるどんな助けも大歓迎です。私が逃したことがあれば、私に知らせてください。私はあなたにそれを得るために全力を尽くします。

ありがとうございました!

答えて

2

これは動作するはずです:

server.modules += ("mod_cgi") 

cgi.assign = (".pl" => "/usr/bin/perl", 
        ".py" => "/usr/bin/python") 

あなたは、Pythonのバージョンは何を実行していますか? python3をアップグレードしてインストールしましたか?そうであれば、python2もインストールして、/usr/bin/python/usr/bin/python2に変更してください。

mimetypesをLighttpdのmimetypes.confファイルに設定しましたか?

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

変更する前に、lighttpdのエラーログを確認しましたか?ログは保存されています/var/log/lighttpd/error.log

あなたは正確な問題は何ですか?ディレクトリに移動すると、ファイルはダウンロードしようとしますか?これ以上の情報なしでトラブルシューティングすることは困難です。

0

OPは私のシステム(Ubuntuの信頼できる)の上に、私はディレクトリ/usr/lib/cgi-bin/script.pyにスクリプトを入れて、URLを使用してブラウザを経由してそれらにアクセスするのに対し、/var/www/cgi-bin/flash.pyでスクリプトを入れて言及:にしようとしたときに、どんな場合でもhttp://localhost/cgi-bin/script.py

、私はこのSO質問に上陸しました:CMDを使用して、CGIモジュールを有効にする、/etc/lighttpd/conf-enabled/10-cgi.conf に入れて再び私の場合には設定が

$HTTP["remoteip"] =~ "127.0.0.1" {  
    alias.url += ("/cgi-bin/" => "/usr/lib/cgi-bin/") 
    $HTTP["url"] =~ "^/cgi-bin/" { 
    cgi.assign = (".sh" => "/bin/sh") 
    } 
} 

だった - ので、参考としてこの情報を入れてlighttpdの中のCGI Pythonスクリプトを動作させる - それ以外の場合はドロレスの答え@十分ですcmdを使ってlighttpdののリロードをやっ、その後:/etc/init.d/lighttpd force-reload

後はscript.py次のとおりです。

import time 
print("Content-Type: text/html\n\n") # html markup follows 

timeStr = time.strftime("%c") # obtains current time 

htmlFormat = """ 
<html> 
<Title>The Time Now</Title> 
<body> 
<p>The current Central date and time is: {timeStr}</p> 
</body> 
</html> """ 

print(htmlFormat.format(**locals())) # see embedded %s^above 
関連する問題