【问题标题】:running a python flask webapp on apache在 apache 上运行 python flask webapp
【发布时间】:2014-09-04 20:19:26
【问题描述】:

我正在尝试在 ubuntu 上的 apache 上运行烧瓶应用程序。 我在浏览器中收到此错误:

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.

即使日志级别为调试,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 脚本,可以使用它自己的独立服务器运行应用程序,如下所示:

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 上运行? 我已经读过: http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/

http://fosshelp.blogspot.in/2014/03/how-to-deploy-flask-application-with.html

【问题讨论】:

  • 当我需要与“python app.py”不同的东西时,我在运行 Python 脚本时遇到了几个问题。然后我弄清楚了 Python 软件应该是什么样子,并创建了一个名为 Machete (pypi.python.org/pypi/machete) 的工具。您可以尝试一下,创建一个空的(但可运行的)flask 应用程序,然后尝试与您的 Apache 配置集成......它可能会工作。 Python 软件结构有点棘手。

标签: apache flask


【解决方案1】:

我设法让它工作。 我没有针对 wsgi 中的 run.py,而是针对具有路由标签的 views.py。 另一个问题是我的 sqlite 数据库没有适当的权限导致应用程序失败,但您不会收到任何错误。 要查看错误,我必须添加:

WSGIRestrictStdout Off

到顶部 /etc/apache2/sites-available/mydomain.com 并添加

sys.stdout = sys.stderr

到我的 wsgi 并使用 python 打印命令添加异常句柄。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-06-12
  • 2014-08-31
  • 1970-01-01
  • 2019-03-24
  • 1970-01-01
  • 1970-01-01
  • 2015-09-26
  • 1970-01-01
相关资源
最近更新 更多