【问题标题】:Problems with deploying flask WSGI application on apache2在 apache2 上部署烧瓶 WSGI 应用程序的问题
【发布时间】:2012-07-28 18:00:24
【问题描述】:

我创建了一个单文件 Flask 应用程序,以便我可以测试如何在 apache2 服务器上部署它。就服务器和 WSGI 配置而言,我按照Flask 上的步骤进行操作。当我指向浏览器中的资源时,它说我没有权限。 WSGI 守护进程被赋予与 Flask 应用程序相同的权限。下面是 VirtualHost 的配置。

<VirtualHost *:80>

ServerName localhost 

WSGIDaemonProcess flask_test user=someuser group=someuser threads=5
WSGIScriptAlias /flask_test/ /var/www/flask_test/flask_test.wsgi

DocumentRoot /var/www/flask_test/
ErrorLog /var/www/flask_test/logs/error.log

    <Directory /var/www/flask_test/>
        WSGIProcessGroup flask_test
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        Order deny,allow
        Deny from all
    </Directory>

</VirtualHost>

这是 WSGI 文件

import sys

activate_this = '/home/someuser/pyProjects/general/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

sys.path.append('/home/someuser/pyProjects')

from general import test as application

最后是 error.log 的输出

[Tue Jul 31 01:51:18 2012] [error] Exception KeyError: KeyError(140345719740224,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored
[Tue Jul 31 01:51:21 2012] [error] [client 108.207.222.48] client denied by server configuration: /var/www/flask_test/flask_test.wsgi
[Tue Jul 31 01:51:21 2012] [error] [client 108.207.222.48] client denied by server configuration: /var/www/flask_test/favicon.ico

编辑:实施 Graham Dumpleton 建议服务器后,现在返回代码 500 并出现以下错误 TypeError: 'module' object is not callable

【问题讨论】:

    标签: python apache2 flask wsgi


    【解决方案1】:

    一般想要:

    WSGIScriptAlias /flask_test/ /var/www/flask_test/flask_test.wsgi
    

    子 URL 的挂载点没有尾部斜杠。

    更糟糕的是你有:

    Deny from all
    

    所以你明确告诉 Apache 返回禁止。

    你应该有:

    Allow from all
    

    在这种情况下。

    【讨论】:

    • 谢谢。我应用了你的建议,看来我越来越接近了。现在我收到 500 错误,并且在错误日志中的 error.log TypeError: 'module' object is not callable 中。有没有办法获得更详细的输出?
    【解决方案2】:

    问题出在 .wsgi 文件中。 我没有正确导入应用程序对象。基本上,您要确保将 app 对象作为应用程序导入 wsgi。例如from flask_test import app as application

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-06
      • 2020-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 2015-11-21
      相关资源
      最近更新 更多