lighttpd, web.py, spawning fcgi failed
2015-11-24 23:34
302 查看
lighttpd, web.py, spawning fcgi failed
基于web.py的程序开发起来还是非常简单的,但是我没想到在服务器上部署的时候却遇到了不少麻烦。我用的 web server 是 lighttpd,不能正常启动,查看错误日志,发现如下几行:
经历了许多周折之后,问题终于解决掉──实际上不是仅仅一个问题。在这儿把经验分享一下,如果有人遇到同样的问题,至少可以少走一些弯路。请按照一下几点检查错误:
检查一下文件的权限,code.py 必须是可执行的。如果没有执行权限,那么给它加上:
同时,要保证文件头部有这样的指令:
一般情况下这个例子是可以正常运行的。这说明可能是我们自己的程序比 hello world 多引用的库出了问题。
打开 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):
基于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 started 2009-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.py 2009-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 web
urls = (
'/(.*)', '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 MySQLdb except 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
相关文章推荐
- odoo worker 异常Exception("bus.Bus unavailable")
- POJ 3691 DNA repair (AC自动机 + dp)
- LightOJ 1038 - Race to 1 Again(期望DP)
- http://m.blog.csdn.net/blog/jimy86022/20995481 [zhuanzai] -------celllinehidden
- leetcode_182_duplicate_emails
- An error has occurred. See error log for more details.关于这个问题的小谈
- Daily Scrum - 11/24
- Time to sail!
- leetcode 70:Climbing Stairs
- 从B树、B+树、B*树谈到R 树 http://blog.csdn.net/v_JULY_v/article/details/6530142/
- POJ 3250-Bad Hair Day【栈】
- CenterOS6.5 配置sendmail
- 在AIX中查看文件大小
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- [转] Bound Service的三种方式(Binder、 Messenger、 AIDL)
- 论垃圾邮件危害性及U-Mail邮件系统必杀技
- 论垃圾邮件危害性及U-Mail邮件系统必杀技
- 论垃圾邮件危害性及U-Mail邮件系统必杀技
- hive查询写文件报错Failed with exception Unable to move source hdfs:xx to destination xxx