3
votes

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). Right now instead of showing the webpages, the URL just give the directories like a ftp. Below is my websitename.wsgi file:

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:

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:

/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?

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 ''.
1
Can you make the hello word from the modwsgi site work? - Clodoaldo Neto
The instructions look not very much complicated, and our computer manager has been playing with the settings for a long time. It still didn't work. Are there some variables there that are particularly critical? - Jingping
Don't add anything to the hello world recipe. Forget about flask, your directory structure and everything else. Just follow the instructions exactly. If the hello world does not work you can't do anything work. - Clodoaldo Neto
Hi Clodoaldo, I added some error msgs. Can you see anything there? - Jingping
couple of questions: What else is in your apache2.conf? this may well be overriding mod_wsgi. Your Apache2.conf above will start the server at http://localhost/websitename, rather than just http://localhost/ is that what you intended? Finally, in your python code, do you have an @app.route('/') decorator in there? or is that also routed to @app.route('/websitename'), which would make the site available at http://localhost/websitename/websitename - MalphasWats

1 Answers

1
votes

I don't know if you are still checking this. Do you have the following lines in your websitename.py

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

Except from Flask Manual:

Problem: application does not run, errorlog shows SystemExit ignored. You have a app.run() call in your application file that is not guarded by an

if __name__ == '__main__': 
    condition.

Hopefully this helps.