【发布时间】:2015-02-17 21:18:53
【问题描述】:
我一直在做 Miguel Grinberg 的 Flask 微博教程,并且一直在尝试部署到我的 linux VPS。(http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux-even-on-the-raspberry-pi)
我收到一个 500 内部服务器错误,这是由 apache 而不是烧瓶产生的,我无法弄清楚。使用解释器运行它时它可以工作,但我不能用 apache 启动它。我已经阅读了很多谷歌搜索和 SO 问题,但我迷路了。我对 linux/python/flask 比较陌生,但我愿意学习是否有人可以为我指明正确的方向。
设置:
我正在使用 Python 2.6.6 和 Apache 2.2.15 运行全新的 CentOS 6.6 安装。我正在使用 sqlite 运行它。如果您有兴趣,我正在使用这些烧瓶模块:http://pastebin.com/bPnH83bs
基本应用结构:(为简洁起见)
位于:/home/apps/portal
我将整个目录改成:chown -R apps:apache
用户 'apps' 是 apache 组的成员
flask\ (virtualenv)
app\
static\
templates\
__init__.py
models.py
views.py
forms.py
decorators.py
db_repository\
search.db\
tmp\
app.db
config.py
run.py
runp.py
runp-sqlite.fcgi
Apache conf 文件设置:
FcgidIPCDir /tmp
AddHandler fcgid-script .fcgi
<VirtualHost *:80>
DocumentRoot /home/apps/portal/app/static
Alias /static /home/apps/portal/app/static
ScriptAlias / /home/apps/portal/runp-sqlite.fcgi/
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log combined
</VirtualHost>
runp-sqlite.fcgi 内容:
#!flask/bin/python
from flipflop import WSGIServer
from app import app
if __name__ == '__main__':
WSGIServer(app).run()
尝试访问页面时 apache 日志出错并收到 500 错误:
[Mon Dec 15 22:21:44 2014] [warn] [client *.*.*.*] mod_fcgid: read data timeout in 40 seconds
[Mon Dec 15 22:21:44 2014] [error] [client *.*.*.*] Premature end of script headers: runp-sqlite.fcgi
我从控制台运行“runp-sqlite.fcgi”时出错:
[root@**** portal]# sudo -u apache ./runp-sqlite.fcgi
Traceback (most recent call last):
File "./runp-sqlite.fcgi", line 6, in <module>
WSGIServer(app).run()
File "/home/apps/portal/flask/lib/python2.6/site-packages/flipflop.py", line 938, in run
sock.getpeername()
socket.error: [Errno 88] Socket operation on non-socket
我检查过的内容:
- 我已禁用 SELinux,因为它导致了另一个问题,但没有解决此问题。
- 检查文件夹是否已分配给正确的用户/组。
- 检查 '/etc/httpd/conf/httpd.conf' 和 '/etc/sysconfig/httpd' PIDFILE 位置是否正确
- 检查 iptables 是否接受到端口 80 和 5000 的流量(用于测试)。如果我删除我添加的 apache 配置,我将成功地从 /var/www/html 提供服务
- 很多很多的谷歌搜索和玩耍
对不起,文字墙,我只是不知道你需要看到什么。如果有人可以提供帮助,我将非常感激。如果这是愚蠢的事情,我道歉。 :)
更新 1:
将 runp-sqlite.fcgi 改为调用 virtualenv:
#!flask/bin/python
activate_this = '/home/apps/portal/flask/bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
from flipflop import WSGIServer
from app import app
if __name__ == '__main__':
WSGIServer(app).run()
现在 apache errors_log 有一个新的错误消息:
[Fri Dec 19 13:43:03 2014] [notice] Apache/2.2.15 (Unix) DAV/2 mod_fcgid/2.3.9 PHP/5.3.3 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations
[Fri Dec 19 13:43:05 2014] [warn] [client 110.143.38.80] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Fri Dec 19 13:43:05 2014] [error] [client 110.143.38.80] Premature end of script headers: runp-sqlite.fcgi
【问题讨论】:
-
您好,这个问题解决了吗?如果是,请发布答案! (我现在面临同样的问题......)
-
@SunQingyao 对不起伙计这是太久以前我不记得我是如何解决的或原因是什么。我现在使用 nginx 完成所有工作,它往往比 apache 更顺畅,尤其是对于像这样的小型项目。
-
感谢您的回复,将尝试 Nginx!
标签: python apache flask mod-wsgi fastcgi