我有一个运行全新安装的 Ubuntu 10.04 LTS 的 VPS。我正在尝试使用 Flask 微框架设置一个实时应用程序,但这给我带来了麻烦。当我试图让它运行时,我做了笔记,这是我的逐次播放,以准确找出我出错的地方。
安装
http://flask.pocoo.org/docs/installation/#installation
$ adduser myapp
$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ sudo pip install virtualenv
/home/myapp/
-- www/
$ sudo pip install virtualenv
/home/myapp/
-- www/
-- env/
$ . env/bin/activate
$ easy_install Flask
MOD_WSGI
http://flask.pocoo.org/docs/deploying/mod_wsgi/
$ sudo apt-get install apache2
$ sudo apt-get install libapache2-mod-wsgi
创建 WSGI 文件
$ nano /home/myapp/www/myapp.wsgi
--myapp.wsgi contents:--------------------------
activate_this = '/home/myapp/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from myapp import app as application
/home/myapp/
-- www/
-- myapp.wsgi
-- env/
配置 Apache
$ nano /etc/apache2/sites-available/myapp.com
-----myapp.com file contents ---------------------
<VirtualHost *:80>
ServerName myapp.com
WSGIDaemonProcess myapp user=myapp group=myapp threads=5 python-path=/home/myapp/env/lib/python2.6/site-packages
WSGIScriptAlias / /home/myapp/www/myapp.wsgi
<Directory /home/myapp/www>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
启用我刚刚创建的虚拟主机文件
$ cd /etc/apache2/sites-enabled
$ ln -s ../sites-available/myapp.com
重启阿帕奇
$ /etc/init.d/apache2 restart
为我提供 500 服务器错误页面。这是最新的错误日志:
mod_wsgi (pid=3514): Target WSGI script '/home/myapp/www/myapp.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=3514): Exception occurred processing WSGI script '/home/myapp/www/myapp.wsgi'.
Traceback (most recent call last):
File "/home/myapp/www/myapp.wsgi", line 4, in <module>
from myapp import app as application
ImportError: No module named myapp
这些错误暗示这是非常明显的事情,但我很迷茫。