Apache + mod_wsgi + Flask(类似于Django)无效

时间:2012-03-08 18:25:08

标签: python apache flask mod-wsgi

我有一个用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 ''.

1 个答案:

答案 0 :(得分:1)

我不知道你是否还在检查这个。你的websitename.py

中有以下几行吗?
if __name__ == '__main__':
    app.run()

除Flask手册:

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

保护
if __name__ == '__main__': 
    condition.

希望这有帮助。