我正在尝试运行一个使用 Flask 微框架开发的非常简单的 Python Web 应用程序。我在使用 Ubuntu 10.04 LTS 的 VPS 上。我已按照此说明获得令人欣慰的“Hello world!”,这是一次成功的体验。但是现在,我正在设置一个稍微复杂的配置,但我无法让它正常工作。
我的应用程序的 Apache 虚拟主机配置是:
<VirtualHost *:80>
ServerAdmin user@example.org
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /srv/www/domain.com/public_html/
LogLevel info # I've put this for debugging purposes.
ErrorLog /srv/www/domain.com/logs/error.log
CustomLog /srv/www/domain.com/logs/access.log combined
WSGIDaemonProcess username user=username group=username threads=5 processes=5
WSGIScriptAlias /myapplication/ /srv/www/domain.com/myapplication/myapplication.wsgi
<Directory /srv/www/domain.com/myapplication/myapplication>
WSGIProcessGroup username
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
Alias /css /srv/www/domain.com/public_html/css
Alias /js /srv/www/domain.com/public_html/js
Alias /images /srv/www/domain.com/public_html/images
</VirtualHost>
我的 WSGI 配置文件是:
# -*- coding: utf-8 -*-
from myapplication import app as application
上面的配置有问题吗?
最后,Apache 给了我一个 500 错误页面。所以我检查了日志:
[info] mod_wsgi (pid=3132, process='', application='domain.com|/myapplication/'): Loading WSGI script '/srv/www/domain.com/myapplication/myapplication.wsgi'.
[error] mod_wsgi (pid=3132): Target WSGI script '/srv/www/domain.com/myapplication/myapplication.wsgi' cannot be loaded as Python module.
[error] mod_wsgi (pid=3132): Exception occurred processing WSGI script '/srv/www/domain.com/myapplication/myapplication.wsgi'.
[error] Traceback (most recent call last):
[error] File "/srv/www/domain.com/myapplication/myapplication.wsgi", line 3, in <module>
[error] from myapplication import app as application
[error] ImportError: No module named myapplication
树形结构如下所示:
/myapplication
myapplication.wsgi
myapplication (python package)
显然,Pythonmyapplication
在sys.path
. 但我已经检查了打印件,它就在那里。我知道这个问题可能很容易解决,但我有点困惑。我怎样才能找到正确的方向来解决这个问题?