在apache上运行python flask webapp

在apache上运行python flask webapp,apache,flask,Apache,Flask,我正试图在ubuntu上的apache上运行flask应用程序。 我在浏览器中遇到以下错误: Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. 即使日志级别为debug,apache日志也不会

我正试图在ubuntu上的apache上运行flask应用程序。 我在浏览器中遇到以下错误:

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
即使日志级别为debug,apache日志也不会指示任何错误。 我的wsgi文件如下所示:

import sys
sys.path.insert(0, '/var/www/myflask/')
from run import app as application
我也试过:

from appimport app as application
没有任何运气。 如果我将wsgi文件内容更改为:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]
然后它就起作用了。 此外,如果我在python控制台中运行wsgi的3行代码,它不会引发任何异常。 我有一个run.py scrpt,它可以使用自己的独立服务器运行应用程序,如下所示:

from flask import Flask
app = Flask(__name__)
from app import app
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000)
以下是文件系统:

├── app
│   ├── db_access.py
│   ├── db_access.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── static
│   ├── templates
│   │   └── index.html
│   ├── views.py
│   └── views.pyc
├── __init__.py
├── __init__.pyc
├── myapp.wsgi
├── requirements.txt
├── run.py
├── run.pyc
有没有办法让它在apache上运行? 我已经读过:


我设法使它工作起来了。 我没有在wsgi中以run.py为目标,而是以views.py为目标,它有路由标记。 另一个问题是,我的sqlite数据库没有适当的权限,这导致应用程序失败,但您不会得到任何错误。 要查看错误,我必须添加:

WSGIRestrictStdout Off
顶 /etc/apache2/sites available/mydomain.com 加


使用python打印命令添加异常句柄。

当需要与“python app.py”不同的东西时,我在运行python脚本时遇到了一些问题。然后我弄明白了Python软件应该是什么样子,并创建了一个名为弯刀()的工具。您可以尝试一下,创建一个空的(但可运行的)flask应用程序,然后尝试与Apache配置集成。。。这可能有用。Python软件结构有点棘手。如果必须对stdout这样做,那么您使用的是一个古老版本的mod_wsgi。你真的应该升级。看到和
sys.stdout = sys.stderr