Apache服务器没有使用与W​​SGI设置适当的virtualenv [英] apache server not using proper virtualenv with WSGI setting

查看:228
本文介绍了Apache服务器没有使用与W​​SGI设置适当的virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的Django WSGI脚本相关的一个问题。我一直在使用两个的virtualenv为我的两个应用程序,我已经部署了我与不同的端口本地服务器上的这些两个应用。对于第一个应用项目Apache配置文件如下:

I am facing a problem related to django wsgi script. I have been using two virtualenv for my two application and I have deployed these two application on my local server with different port. Apache configuration file for first Appplication looks like:

listen 8081
WSGIPythonPath /home/user/app1:/home/user/virtual-env1/lib/python2.7/site-packages
<VirtualHost mylocalip:8081>

        ServerAdmin webmaster@localhost

        ServerName www.app1.com

        DocumentRoot /home/user/app1

        <Directory /home/user/app1/static-root>
                Options Indexes
                Order Allow,Deny
                Allow from all
                IndexOptions FancyIndexing
        </Directory>

       <Directory /home/user/app1>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all         
        </Directory>

        WSGIScriptAlias / /home/user/app1/django.wsgi
        WSGIPassAuthorization On
            Alias "/static" /home/user/workspace/app1/static_root

</VirtualHost>

和第二个应用程序的Apache配置几乎是相同的,但不是虚拟ENV1,我使用虚拟ENV2和不同的端口。但是,当我在服务器上运行我的第二个应用程序,我得到这个错误。

and Apache configuration for second application is almost same but instead of virtual-env1, I am using virtual-env2 and different port. But when I run my second application on the server I got this error.

**AttributeError at /**
  'Settings' object has no attribute 'DB_FILES'
         Request Method:    GET
         Request URL:   http://mylocalip:8091/
         Django Version:    1.4.3
         Exception Type:    AttributeError
         Exception Value:   'Settings' object has no attribute 'DB_FILES'
         Exception Location: /home/user/virtual-env1/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185
         Python Executable: /usr/bin/python
         Python Version:    2.7.2
         Python Path:   
         ['/home/user/virtual-env1/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
         '/home/user/virtual-env1/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
         '/home/user/app1',
         '/home/user/virtual-env1/lib/python2.7/site-packages',
         '/usr/local/lib/python2.7/dist-packages/pip-1.1-py2.7.egg',
         '/usr/local/lib/python2.7/dist-packages',
         '/usr/lib/python2.7',
         '/usr/lib/python2.7/plat-linux2',
         '/usr/lib/python2.7/lib-tk',
         '/usr/lib/python2.7/lib-old',
         '/usr/lib/python2.7/lib-dynload',
         '/usr/local/lib/python2.7/dist-packages',
         '/usr/lib/python2.7/dist-packages',
         '/usr/lib/python2.7/dist-packages/PIL',
         '/usr/lib/python2.7/dist-packages/gst-0.10',
         '/usr/lib/python2.7/dist-packages/gtk-2.0',
         '/usr/lib/pymodules/python2.7',
         '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
         '/usr/lib/python2.7/dist-packages/ubuntuone-client',
         '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
         '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
         '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
         '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
         '/home/user/app2',
         '/home']

我django.wsgi文件loks是这样的:

My django.wsgi file loks like this:

import os, sys

apache_configuration = os.path.dirname (__file__)

project = os.path.dirname (apache_configuration)

workspace = os.path.dirname (project)

sys.path.append ("/home/user/app2")

sys.path.append (workspace)

os.environ ['DJANGO_SETTINGS_MODULE'] = 'app2.settings'


import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler ()

我不知道为什么我的服务器正在虚拟-ENV1,而不是虚拟ENV2内。请帮助我,因为我是新来的Django和WSGI。

I don't know why my server is looking inside the virtual-env1 instead of virtual-env2. Please help me as I am new to django and wsgi.

推荐答案

下面就是在类似的情况帮助了我。

Here's what helped me in similar situation.

我的WSGI文件看起来像这样:

My wsgi file looks like this:

import os
import sys

# activate venv
activate_this = 'full_path_to_activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

# insert project path to sys path
path = 'full_path_to_your_project'
if path not in sys.path:
    sys.path.insert(0, path)

import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'your_settings'
application = django.core.handlers.wsgi.WSGIHandler()

可能这是不是最好的方法,但它为我工作。

May be this isn't the best approach, but it worked for me.

我记得我GOOGLE了,发现了很多不同的解决方案,这里的一些相关链接:

I remember that I've googled and found many different solutions, here's some related links:

  • Setting up Apache and Python WSGI to use VirtualEnv
  • Setting up django on apache (mod_wsgi, virtualenv)
  • Django Apache wsgi virtualenv import error

希望有所帮助。

这篇关于Apache服务器没有使用与W​​SGI设置适当的virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆