sco*_*ooz 10 apache deployment django mod-wsgi virtualenv
在过去两个月与django的开发服务器合作之后,时间终于转移到了apache + mod_wsgi.
问题是,当我访问我的网站(让我们称之为junux),到映射到django应用程序的URL时,事情似乎不起作用.在服务器上运行开发服务器时,事情正常.
错误的底线是在apache error_log中给出的:
ImportError:无法导入设置'junux_site.settings'(是否在sys.path上?):没有名为importlib的模块
我知道这类似于对此事的许多其他问题(有这么多,我甚至不会说出来了这里),但我还没有找到答案.我已经阅读了很多关于转向生产的指南,包括django的部署文档,mod_wsgi的指南,一些pycon演示文稿,并且一直在谷歌上搜索这个问题......
下面有很多有趣和令人兴奋的细节.
任何帮助将不胜感激.提前致谢.
配置:
这是apache返回的错误页面:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Apache/2.2.15 (CentOS) Server at junux.net Port 80
Run Code Online (Sandbox Code Playgroud)
apache error_log
显示以下信息:
mod_wsgi (pid=22502): Create interpreter 'junux.net|/dev'.
mod_wsgi (pid=22502): Exception occurred processing WSGI script '/var/www/junux_dev/junux_site/wsgi.py'.
Traceback (most recent call last):
File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 219, in __call__
self.load_middleware()
File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 39, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/var/www/junux_dev/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'junux_site.settings' (Is it on sys.path?): No module named importlib
Run Code Online (Sandbox Code Playgroud)
相关wsgi.py
:
import os
import sys
import site
# use our virtual environment
SITE_DIR = os.path.dirname(__file__)
PROJECT_ROOT = os.path.dirname(SITE_DIR)
site_packages = os.path.join(PROJECT_ROOT, 'venv/lib/python2.7/site-packages')
site.addsitedir(os.path.abspath(site_packages))
sys.path.insert(0, SITE_DIR)
sys.path.insert(1, PROJECT_ROOT)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "junux_site.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Run Code Online (Sandbox Code Playgroud)
并且httpd.conf
:(来自默认的apache配置文件的更多内容)
<VirtualHost *:80>
ServerName junux.net
ServerAlias junux.net
ServerAdmin admin@junux.net
WSGIScriptAlias /test /var/www/test/hello.py
WSGIScriptAlias /dev /var/www/junux_dev/junux_site/wsgi.py
<Directory /var/www/test >
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/junux_dev >
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
LogLevel info
Run Code Online (Sandbox Code Playgroud)
有一个WSGIScriptAlias
以/test
提供完整性检查是确实的mod_wsgi工作.确实如此.当打开该URL时(非常简单)应用程序工作(典型的hello世界).
我已设置权限,chmod o+r
在我的WSGI文件,并chmod o+rx
在整个/var/www/junux_dev
目录,如从refered到PYCON悉尼- 2010演示文稿指示在这里.
Gra*_*ton 15
什么版本的Python是mod_wsgi编译的?看起来您可能在系统上安装了多个Python,而您的虚拟环境使用的是Python 2.7,但您的mod_wsgi是针对2.6编译的.
基于这个猜测是因为importlib仅在Python 2.7中添加,所以如果mod_wsgi是为2.6编译并使用该基本安装,那么将无法找到importlib.
运行检查:
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Installation_In_Use
归档时间: |
|
查看次数: |
8231 次 |
最近记录: |