注意:我发现了五个关于破坏“hello world on flask / mod_wsgi”实现的问题。我查看了所有这些内容,但找不到自己破解的实现方案。因此,请不要太匆忙将此问题视为重复。
我正在管理云Ubuntu VM。目前它正在运行LAMP堆栈。在我的webroot中,我有一个mediawiki和一些HTML文件,如http://pipad.org/ball/multiball.html - 一切运行正常。
现在我正在尝试让http://pipad.org/foo使用Flask和Apache / mod_wsgi为Python后端动态生成页面。
不幸的是,将浏览器导航到http://pipad.org/foo会导致“找不到网址”。
以下是我的文件:
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>
根据上述配置文件中的评论,......
pi@PiDroplet:~/web/piFlask$ tail -n 2 /etc/apache2/apache2.conf
Include /home/pi/web/piFlask/apache.conf
有人能看到我错过的东西吗?
答案 0 :(得分:3)
您可能必须在Flask config中将APPLICATION_ROOT
变量设置为'/foo'
。
<强> piFlask.py 强>
from flask import Flask
app = Flask(__name__)
app.config['APPLICATION_ROOT'] = '/foo'
@app.route('/')
def hello_world():
return 'Hello World!'
答案 1 :(得分:2)
这应该解决它:
<VirtualHost *:80>
注意: