我正试图使我的烧瓶应用程序在CentOS服务器上工作。基本上,问题是我在/usr/bin
中安装了Python 2.6,这是系统默认值,在/usr/local/bin
中安装了Python 3.4。我想使用Python 3.4virtualenv或者至少python3.4解释器来运行我的应用程序。
我已经在~/virtualenvs/flask
中创建了virtualenv。
我有这个WSGI脚本:
import os
import sys
from logging import Formatter, FileHandler
APP_HOME = r"/home/fenikso/Album"
activate_this = os.path.join("/home/fenikso/virtualenvs/flask/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
sys.path.insert(0, APP_HOME)
os.chdir(APP_HOME)
from app import app
handler = FileHandler("app.log")
handler.setFormatter(Formatter("[%(asctime)s | %(levelname)s] %(message)s"))
app.logger.addHandler(handler)
application = app
在Apache中执行以下配置:
<VirtualHost *:80>
ServerName album2.site.cz
Alias /static "/home/fenikso/Album/static"
Alias /photos "/home/fenikso/Album/photos"
Alias /thumbs "/home/fenikso/Album/thumbs"
WSGIScriptAlias / "/home/fenikso/Album/wsgi.py"
<Directory "/home/fenikso/Album">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/static">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/photos">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/thumbs">
AllowOverride None
Allow from all
</Directory>
</VirtualHost>
但是,当尝试运行应用程序时,我得到一个错误:
Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 mod_fcgid/2.3.7 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips SVN/1.6.11 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
mod_wsgi (pid=14627): Target WSGI script '/home/fenikso/Album/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=14627): Exception occurred processing WSGI script '/home/fenikso/Album/wsgi.py'.
Traceback (most recent call last):
File "/home/fenikso/Album/wsgi.py", line 15, in <module>
from app import app
File "/home/fenikso/Album/app.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
我注意到Python 2.6正在运行,而我的virtualenv没有被激活。有什么方法可以让这个工作正常,并且仍然将Python2.6作为系统默认值?
查看WSGIPythonHome and WSGIPythonPath指令。还可能安装了python2.6mod_wsgi,必须为预期的python版本和does not support multiple python versions编译mod_wsgi。因此,请检查mod_wsgi是否与py3.4兼容,并设置上面的指令。
或者,您可以使用一个python服务器运行flask应用程序,比如gunicorn和proxypass,从apache到gunicorn。
您必须在apache.conf中添加以下行,以便提供正确的可执行文件和virtualenv的路径。
您将找到这两个命令的所有选项in the mod_wsgi documentation
请注意,mod_wsgi的版本必须与python可执行文件兼容。在您的例子中,您可能需要安装mod_wsgi3.4并配置apache来使用它,而不是standart mod_wsgi模块。
整个配置文件应该是:
相关问题 更多 >
编程相关推荐