【问题标题】:Flask app on Apache, CentOs throws mod_fcgid: error reading data from FastCGI serverApache 上的 Flask 应用程序,CentOs 抛出 mod_fcgid:从 FastCGI 服务器读取数据时出错
【发布时间】:2015-07-13 01:48:02
【问题描述】:

我正在基于 Apache 和 Mysql 的 CentOS 6.6 上开发 Flask 应用程序。修改自The Flask Megatutorial。我可以正常创建数据库,但是当我尝试从浏览器访问它时,出现 500 内部服务器错误,并且在 error_log 文件中:

content type: text/html



<h1>Hello world!</h1>
[Sun May 03 18:39:53 2015] [error] [client my.ip.add.res] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Sun May 03 18:39:53 2015] [error] [client my.ip.add.res] Premature end of script headers: runp-mysql.fcgi

这是在我将 runp-mysql.fcgi 文件编辑为以下内容之后:

#!flask/bin/python
#encoding=UTF-8
#import os

print "content type: text/html\n\n"
print ""
print "<h1>Hello world!</h1>"

从命令行运行它可以正确完成。

我的 httpd.conf 文件以此结尾:

FcgidIPCDir /tmp
AddHandler fcgid-script .fcgi
<VirtualHost *:80>
    DocumentRoot /home/apps/my_app/app/static
    Alias /static /home/apps/my_app/app/static
    ScriptAlias / /home/apps/my_app/runp-mysql.fcgi/
</VirtualHost>

【问题讨论】:

  • 为什么你的.fcgi 文件中有打印语句?该错误是此“脚本头过早结束”的直接后果。
  • 好的,这是几个月前的事了,我已经解决了(问题的确切根源是 python 模块在这个版本的 python 下不起作用,我将添加这个作为帮助的答案还有谁)。至于为什么我有打印语句,我在某处读到预期的脚本头只是一个内容类型的 html 头,只是试图部署一个简单的应用程序。

标签: python apache flask centos mod-fcgid


【解决方案1】:

我也在做同样的事情,一个主要问题是文件的权限。确保它是可执行的而不是只读的。

我也不认为 runp-mysql.fcgi 是您想要打印的地方。它应该在视图文件中。这是你应该连接到你的 mysql 数据库然后启动 wscgi 服务器的地方。

【讨论】:

    【解决方案2】:

    根据我的实际问题,这是一个非常松散的答案,我只上传它以防其他人遵循相同的教程并且也有部署问题。 它的要点是在我用于部署的python版本(2.7)下,触发器模块不起作用,我不得不使用flup。对于遇到相同错误的任何人 - 尝试一下,它可能会起作用。

    【讨论】:

      猜你喜欢
      • 2017-09-30
      • 2014-10-27
      • 2012-08-22
      • 2014-10-16
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 2022-06-20
      相关资源
      最近更新 更多