【问题标题】:Apache + mod_wsgi + Flask(similar to Django) not workingApache + mod_wsgi + Flask(类似于 Django)不工作
【发布时间】:2012-03-26 05:44:27
【问题描述】:

我有一个使用 Python 框架 Flask(类似于 Django)编写的网站,但我无法按照它提供的指令部署它(在 Ubuntu 服务器上使用 Apache2 和 mod_wsgi)。现在 URL 不再显示网页,而是像 ftp 一样提供目录。下面是我的 websitename.wsgi 文件:

import sys
sys.path.insert(0, '/var/www/websitename')

from websitename import app as application

下面是我插入apache2.conf的部分:

ServerName localhost

WSGIDaemonProcess websitename user=www-data group=www-data threads=5
WSGIScriptAlias /websitename /var/www/websitename/websitename.wsgi

<Directory /var/www/websitename >
    WSGIProcessGroup websitename
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

而 /var/www/websitename 目录如下所示:

/websitename
/websitename.py
/static
    /style.css
/templates
    layout.html
    index.html
    login.html
    ...
/scripts
    __init__.py
    somescript.py

任何人都可以提出一些建议是什么问题? Apache.conf?

更新: 我们收到如下错误消息。有什么提示吗?

[Mon Mar 12 12:23:32 2012] [error] [client 157.55.17.200] File does not exist: /var/www/robots.txt
[Mon Mar 12 12:23:33 2012] [notice] caught SIGTERM, shutting down
[Mon Mar 12 12:23:34 2012] [warn] mod_wsgi: Compiled for Python/2.7.2rc1.
[Mon Mar 12 12:23:34 2012] [warn] mod_wsgi: Runtime using Python/2.7.2+.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31835): Starting process 'mywsgiapp' with uid=33, gid=33 and threads=5.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31835): Initializing Python.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31836): Initializing Python.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31837): Initializing Python.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31838): Initializing Python.
[Mon Mar 12 12:23:34 2012] [notice] Apache/2.2.20 (Ubuntu) PHP/5.3.6-13ubuntu3.6 with Suhosin-Patch mod_wsgi/3.3 Python/2.7.2+ configured -- resuming normal operations
[Mon Mar 12 12:23:34 2012] [info] Server built: Feb 14 2012 16:35:35
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31840): Initializing Python.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31839): Initializing Python.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31835): Attach interpreter ''.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31836): Attach interpreter ''.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31838): Attach interpreter ''.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31837): Attach interpreter ''.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31840): Attach interpreter ''.
[Mon Mar 12 12:23:34 2012] [info] mod_wsgi (pid=31839): Attach interpreter ''.
[Mon Mar 12 12:25:41 2012] [error] [client 128.192.240.] File does not exist: /var/www/favicon.ico
[Mon Mar 12 12:25:41 2012] [info] mod_wsgi (pid=13463): Initializing Python.
[Mon Mar 12 12:25:41 2012] [info] mod_wsgi (pid=13463): Attach interpreter ''.
[Mon Mar 12 12:26:27 2012] [error] [client 128.192.240.] File does not exist: /var/www/favicon.ico
[Mon Mar 12 12:26:27 2012] [info] mod_wsgi (pid=17315): Initializing Python.
[Mon Mar 12 12:26:27 2012] [info] mod_wsgi (pid=17315): Attach interpreter ''.
[Mon Mar 12 12:26:28 2012] [info] mod_wsgi (pid=17367): Initializing Python.
[Mon Mar 12 12:26:28 2012] [info] mod_wsgi (pid=17368): Initializing Python.
[Mon Mar 12 12:26:28 2012] [info] mod_wsgi (pid=17367): Attach interpreter ''.
[Mon Mar 12 12:26:28 2012] [info] mod_wsgi (pid=17368): Attach interpreter ''.
[Mon Mar 12 12:26:31 2012] [info] mod_wsgi (pid=17559): Initializing Python.
[Mon Mar 12 12:26:31 2012] [info] mod_wsgi (pid=17559): Attach interpreter ''.

【问题讨论】:

  • 你能让来自modwsgi 网站的你好词起作用吗?
  • 指令看起来不是很复杂,我们的电脑管理员玩了很久的设置。它仍然没有工作。是否有一些特别重要的变量?
  • 不要在 hello world 食谱中添加任何东西。忘记烧瓶,你的目录结构和其他一切。只需完全按照说明进行操作。如果 hello world 不工作,你就什么都做不了。
  • 嗨 Clodoaldo,我添加了一些错误消息。你能看到什么吗?
  • 几个问题:你的 apache2.conf 中还有什么?这很可能会覆盖 mod_wsgi。您上面的 Apache2.conf 将在http://localhost/websitename 启动服务器,而不仅仅是http://localhost/ 是您想要的吗?最后,在你的 python 代码中,你有一个 @app.route('/') 装饰器吗?或者是否也路由到@app.route('/websitename'),这将使该站点在http://localhost/websitename/websitename 可用

标签: python apache flask mod-wsgi


【解决方案1】:

我不知道你是否还在检查这个。您的 websitename.py 中有以下几行

if __name__ == '__main__':
    app.run()

Flask 手册除外:

问题:应用程序没有运行,错误日志显示 SystemExit 被忽略。 您的应用程序文件中有一个 app.run() 调用,该调用不受

if __name__ == '__main__': 
    condition.

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-18
    • 2011-07-29
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2011-04-02
    • 1970-01-01
    相关资源
    最近更新 更多