Reputation: 30724
NOTE: I've found five questions regarding broken "hello world on flask/mod_wsgi" implementations. I have looked through all of them, and can't find the solution to my own broken implementation. So please don't be too hasty to close this question as a duplicate.
I'm administering a cloud Ubuntu VM. Currently it's running a LAMP stack. In my webroot I've got a mediawiki and a few HTML files like http://pipad.org/ball/multiball.html -- everything is running okay.
Now I'm trying to have http://pipad.org/foo serve a page dynamically generated by a Python backend, using Flask and Apache/mod_wsgi.
Unfortunately navigating my browser to http://pipad.org/foo results in "URL not found".
Here are my files:
pi@PiDroplet:~/web/piFlask$ pwd
/home/pi/web/piFlask
pi@PiDroplet:~/web/piFlask$ ls -l
total 24
-rw-r--r-- 1 root root 628 May 15 02:37 apache.conf
-rwxrwxr-x 1 pi pi 153 May 15 02:39 piFlask.py
-rwxrwxr-x 1 pi pi 379 May 15 02:38 piFlask.wsgi
drwxrwxr-x 5 pi pi 4096 May 14 09:06 venv
piFlask.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
# if __name__ == '__main__':
# app.run()
piFlask.wsgi
# http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/#creating-a-wsgi-file
# http://www.enigmeta.com/2012/08/16/starting-flask/
import os, sys
PROJECT_DIR = '/home/pi/web/piFlask'
activate_this = os.path.join(PROJECT_DIR, 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
sys.path.insert(0, PROJECT_DIR)
from piFlask import app as application
apache.conf
pi@PiDroplet:~/web/piFlask$ cat apache.conf
# Look in http://wiki.apache.org/httpd/DistrosDefaultLayout & find equiv to /usr/local/apache2/conf/httpd.conf
# for me (Ubuntu) it's /etc/apache2/apache2.conf
#
# append:
# Include /path/to/this/file
# http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/#configuring-apache
<VirtualHost *>
ServerName pipad.org
WSGIDaemonProcess piFlask user=pi group=pi threads=5
WSGIScriptAlias /foo /home/pi/web/piFlask/piFlask.wsgi
<Directory /home/pi/web/piFlask>
WSGIProcessGroup piFlask
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
And as per the comment in the above config file, ...
pi@PiDroplet:~/web/piFlask$ tail -n 2 /etc/apache2/apache2.conf
Include /home/pi/web/piFlask/apache.conf
Can anyone see what I'm missing?
Upvotes: 4
Views: 1352
Reputation: 32746
You probably have to set APPLICATION_ROOT
variable to '/foo'
in Flask config.
piFlask.py
from flask import Flask
app = Flask(__name__)
app.config['APPLICATION_ROOT'] = '/foo'
@app.route('/')
def hello_world():
return 'Hello World!'
Upvotes: 3
Reputation: 31
This should fix it:
<VirtualHost *:80>
Note:
Upvotes: 2