在apache2

时间:2015-08-27 10:30:50

标签: python apache flask wsgi

我在使用mod_wsgi在apache2上部署烧瓶应用程序时遇到问题。错误日志和配置文件如下。我总是得到内部服务器错误。这与How to solve import errors while trying to deploy Flask using WSGI on Apache2非常相似,但出于某种原因,那里提出的解决方案在这里没有用。

apache错误日志

[Thu Aug 27 12:06:30.366817 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] mod_wsgi (pid=9330): Target WSGI script '/var/www/bitcones/bitcones.wsgi' cannot be loaded as Python module.
[Thu Aug 27 12:06:30.366867 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] mod_wsgi (pid=9330): Exception occurred processing WSGI script '/var/www/bitcones/bitcones.wsgi'.
[Thu Aug 27 12:06:30.366894 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] Traceback (most recent call last):
[Thu Aug 27 12:06:30.366913 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904]   File "/var/www/bitcones/bitcones.wsgi", line 4, in <module>
[Thu Aug 27 12:06:30.366969 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904]     from bitcones import bitcones as application
[Thu Aug 27 12:06:30.366981 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904]   File "/var/www/bitcones/bitcones/bitcones.py", line 6, in <module>
[Thu Aug 27 12:06:30.367045 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904]     from analysis import cone as _cone, flow
[Thu Aug 27 12:06:30.367056 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904]   File "/var/www/bitcones/bitcones/analysis/cone.py", line 5, in <module>
[Thu Aug 27 12:06:30.367121 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904]     from analysis.statistics import purity_statistics
[Thu Aug 27 12:06:30.367139 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] ImportError: No module named analysis.statistics

bitcones.wsgi

#!/usr/bin/python
import sys
sys.path.insert(0,"/var/www/bitcones")
from bitcones import bitcones as application

apache虚拟主机文件

<VirtualHost *:80>
    ServerName <my-server-name>
    ServerAdmin <my-email>
    WSGIDaemonProcess bitcones user=<my-username> group=<my-username> threads=5
    WSGIScriptAlias / /var/www/bitcones/bitcones.wsgi

<Directory /var/www/bitcones>
    WSGIProcessGroup bitcones
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

我的应用树的一部分(一切都在/ var / www / bitcones /下)

├── bitcones
│   ├── analysis
│   │   ├── <some_files>
│   │   └── statistics
│   │   │   ├── <some_files>
│   ├── bitcones.py
│   ├── static
│   │   ├── <some static content>
│   └── templates
│       └── <my_templates>.html
└── bitcones.wsgi

这应该足以弄清楚为什么我有这个导入错误。 如果需要任何其他文件/配置,请询问。我在失去理智。

谢谢!

编辑: 我只想补充说我正在遵循本指南:http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/

1 个答案:

答案 0 :(得分:1)

设置mod_wsgi在安装libapache2-mod-wsgi(python 2)或libapache2-mod-wsgi-py3(python 3)时使用的Python版本。我猜你会用你所描述的Python 2,因为使用python 3是比2更慎重的选择。但我不认为这是你的问题。我认为这是一个导入问题,就像格雷厄姆所说的那样。

我建议您使用from bitcones.analysis.statistics import purity_statistics作为导入语句。