简体   繁体   English

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

[英]Apache + mod_wsgi + Flask(similar to Django) not working

I have a website written with the Python framework Flask (similar to Django), but I cannot deploy it with the instructions it gave (using Apache2 and mod_wsgi on a Ubuntu server). 我有一个用Python框架Flask编写的网站(类似于Django),但是我不能用它给出的指令部署它(在Ubuntu服务器上使用Apache2和mod_wsgi)。 Right now instead of showing the webpages, the URL just give the directories like a ftp. 现在,URL不是显示网页,而是给出像ftp这样的目录。 Below is my websitename.wsgi file: 下面是我的websitename.wsgi文件:

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

from websitename import app as application

And below is the part I inserted into apache2.conf: 下面是我插入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>

And /var/www/websitename directory look like this: / var / www / websitename目录如下所示:

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

Could anyone give some suggestions what is the problem? 谁能提出一些建议是什么问题? Apache.conf? 的apache.conf?

UPDATE: We got error msgs like below. 更新:我们得到了如下错误消息。 Any hints? 任何提示?

[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 ''.

I don't know if you are still checking this. 我不知道你是否还在检查这个。 Do you have the following lines in your websitename.py 您的websitename.py中是否包含以下行?

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

Except from Flask Manual: 除Flask手册外:

Problem : application does not run, errorlog shows SystemExit ignored. 问题 :应用程序未运行,errorlog显示SystemExit被忽略。 You have a app.run() call in your application file that is not guarded by an 您的应用程序文件中有一个app.run()调用,该调用没有受到保护

if __name__ == '__main__': 
    condition.

Hopefully this helps. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM