我正试图在windows环境中使我在python 2.7中的web.py应用程序达到本文所述的生产级别。所以我推荐
生产-->LightTPD-->。。使用FastCGI
部分。首先安装烟道,然后添加
#!/usr/bin/env python
到我的Code.py
然后我从这里下载了lighttpd,并提取了lighttpd-1.4.39-1-IPv6-Win32-SSL.zip。
接下来,我编辑了文档中提到的lighttpd.conf。由于我使用Windows,我使用完整路径使其工作如下。
server.modules = ("mod_fastcgi", "mod_rewrite")
server.document-root = "C:Python27New folderLightTPD-1.4.39-1-IPv6-Win32-SSLLightTPDhtdocsEngine"
fastcgi.server = ( "Code.py" =>
(( "socket" => "C:Python27New folderLightTPD-1.4.39-1-IPv6-Win32-SSLLightTPDhtdocsEnginetmpfastcgi.socket",
"bin-path" => "C:Python27New folderLightTPD-1.4.39-1-IPv6-Win32-SSLLightTPDhtdocsEngineCode.py",
"max-procs" => 1
))
)
url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/(.*)$" => "/Code.py/$1"
)
这是我的Code.py
#!/usr/bin/env python
__author__ = 'Marlon'
import web
import json
import time
urls = (
'/foo(.*)', 'Foo'
)
class Foo(web.storage):
def GET(self,r):
web.header('Access-Control-Allow-Origin', '*')
web.header('Access-Control-Allow-Credentials', 'true')
result = time.sleep(30)
return result
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
当我尝试从命令提示符运行LightTPD.exe时,它会给我这个错误。
2016-07-20 00:02:23: (server.c.645) trying to read configuration (test mode)
2016-07-20 00:02:23: (log.c.194) server started
2016-07-20 00:02:23: (mod_fastcgi.c.1102) the fastcgi-backend C:Python27New folderLightTPD-1.4.39-1-IPv6-Win32-SSLLightTPDhtdocEngineCode.py failed to start:
2016-07-20 00:02:23: (mod_fastcgi.c.1106) child exited with status 2 C:Python27New folderLightTPD-1.4.39-1-IPv6-Win32-SSLLightTPDhtdocEngineCode.py
2016-07-20 00:02:23: (mod_fastcgi.c.1109) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.nIf this is PHP on Gentoo, add 'fastcgi' to the USE flags.
2016-07-20 00:02:23: (mod_fastcgi.c.1395) [ERROR]: spawning fcgi failed.
2016-07-20 00:02:23: (server.c.1057) Configuration of plugins failed. Going down
我需要安装任何与FastCGI相关的东西吗?我遇到过这个要求安装这个,但那不适用于windows。我需要为windows单独安装吗?如果需要,我在哪里可以买到?出现上述错误是问题吗?
请尝试本周早些时候发布的lighttpd 1.4.40。它在Windows上运行得比以前的版本好得多。您需要一个cygwin环境来从源代码构建它,但是可执行文件可以在cygwin外部运行。