lighttpd, web.py, spawning fcgi failed
来源:互联网 发布:艾美仕怎么样 知乎 编辑:程序博客网 时间:2024/06/02 04:46
lighttpd, web.py, spawning fcgi failed
基于web.py的程序开发起来还是非常简单的,但是我没想到在服务器上部署的时候却遇到了不少麻烦。我用的 web server 是 lighttpd,不能正常启动,查看错误日志,发现如下几行:
2009-12-15 19:48:04: (server.c.1503) server stopped by UID = 0 PID = 25128 2009-12-15 19:48:30: (log.c.166) server started2009-12-15 19:48:30: (mod_fastcgi.c.1104) the fastcgi-backend /var/www/code.py failed to start:2009-12-15 19:48:30: (mod_fastcgi.c.1108) child exited with status 1 /var/www/code.py2009-12-15 19:48:30: (mod_fastcgi.c.1111) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.If this is PHP on Gentoo, add 'fastcgi' to the USE flags.2009-12-15 19:48:30: (mod_fastcgi.c.1399) [ERROR]: spawning fcgi failed. 2009-12-15 19:48:30: (server.c.931) Configuration of plugins failed. Going down.
经历了许多周折之后,问题终于解决掉──实际上不是仅仅一个问题。在这儿把经验分享一下,如果有人遇到同样的问题,至少可以少走一些弯路。请按照一下几点检查错误:
code.py 可以执行吗?
当然你可能没有用 code.py 这个名字,我给可执行文件的名字是 root.py
检查一下文件的权限,code.py 必须是可执行的。如果没有执行权限,那么给它加上:
# chmod 755 code.py
同时,要保证文件头部有这样的指令:
#!/usr/bin/env python
hello world 的例子可以正常运行吗?
把你的 code.py 的内容用 web.py 首页的例子替换(别忘了加上第一行的指令):
#!/usr/bin/env pythonimport weburls = ( '/(.*)', 'hello')app = web.application(urls, globals())class hello: def GET(self, name): if not name: name = 'world' return 'Hello, ' + name + '!'if __name__ == "__main__": app.run()
一般情况下这个例子是可以正常运行的。这说明可能是我们自己的程序比 hello world 多引用的库出了问题。
检查一下 egg cache 的权限
我的程序要链接 MySQL 数据库,所以用到了 MySQL-python,启动失败肯定有它的份。现在试试在 hello world 里加上 import MySQLdb,果然不能启动了!为了看到原因,我们用 try-except 来捕获 import MySQLdb 引发的异常,并且把它输出到网页上。把上面 hello 类的 GET 函数改成:
try: import MySQLdbexcept Exception, e: return str(e);return 'hello'
打开 localhost:8080, 我看到了如下的错误信息:
Can’t extract file(s) to egg cache The following error occurred while trying to extract file(s) to the Python egg cache: [Errno 13] Permission denied: ‘/sbin/.python-eggs’ The Python egg cache directory is currently set to: /sbin/.python-eggs Perhaps your account does not have write access to this directory? You can change the cache directory by setting the PYTHON_EGG_CACHE environment variable to point to an accessible directory.
又是权限问题,解决办法有很多种,我就把它的 owner 改成了运行 lighttpd 的用户(我配置文件里写的是 daemon):
chown -R daemon.daemon /sbin/.python-eggs
lighttpd 使用的是哪个 python?
lighttpd 执行环境的环境变量可能和你在 shell 里使用的是不一样的!我有两个 python,一个是 CentOS 自带的老旧 python 2.4,另一个是我后来自己编译的 python 2.6,在我的 $PATH 里,python 2.6 所在的目录是优先的,但是后来发现 lighttpd 使用的竟然是旧的 python 2.4!如果是这样,比较简单的办法就是在 code.py 的头部写上 python 2.6 的完整路径,比如我的:
#!/usr/local/bin/python
还是没有解决?暂时我也想不到了……
- lighttpd, web.py, spawning fcgi failed
- lighttpd + web.py
- LIGHTTPD+FASTCGI+WEB.PY ON DEBIAN
- Linux配置Lighttpd+Python+web.py应用
- Lighttpd + PHP(fcgi)
- Cygwin运行Lighttpd + FCGI + PHP
- web+fcgi
- Web.py下Lighttpd URL重写的问题
- redhat环境下lighttpd+flup+web.py架设笔记
- web.py (url.py)
- Lighttpd搭建Web环境
- web.py
- web.py
- web.py
- web.py
- FCGI
- fcgi.py 从python2.x到3.x的移植
- Failed at step NAMESPACE spawning /usr/lib/systemd/systemd-hostnamed
- 日语数字表达方法
- php页面判断是 iphone还是andriod的浏览器&通过 URL types在浏览器打开app
- 程序员编程艺术第一~十章集锦与总结(教你如何编程)--持续更新中
- linux创建一个.txt类型的文件
- Android中的xmlns
- lighttpd, web.py, spawning fcgi failed
- cronexpression
- 树莓派home目录
- zk系列-zookeeper概述
- MySQL MyISAM InnoDB 简述
- 目录指南
- HDU 5035(未AC)
- FPGA笔记
- 程序员编程艺术:第四章、现场编写类似strstr/strcpy/strpbrk的函数