如何在一个Web服务器上的不同域下运行不同的Django项目?

时间:2013-01-10 05:50:31

标签: python django linux apache http

我正在尝试在我的Web服务器中运行两个不同的项目。我希望它们被不同的域指向。所以我配置了我的httpd.conf:

NameVirtualHost *:80
<VirtualHost *:80>

    ServerAdmin me@web1.com
    ServerName www.web1.com
    WSGIScriptAlias / /var/www/web1/web1/wsgi.py


    <Directory /var/www/web1/web1>
    <Files wsgi.py>
    Order deny,allow
    Allow from all
    </Files>
    </Directory>

    ErrorLog logs/dummy-host.web1.com-error_log
</VirtualHost>

<VirtualHost *:80>

    ServerAdmin me@web2.com
    ServerName www.web2.com
    ServerAlias web2.com *.web2.com
    WSGIScriptAlias / /var/www/web2/web2/wsgi.py

    <Directory /var/www/web2/web2>
    <Files wsgi.py>
    Order deny,allow
    Allow from all
    </Files>
    </Directory>

    ErrorLog logs/dummy-host.web2.com-error_log
</VirtualHost>

使用此配置,我可以运行httpd并成功访问web1.com。但是,当我尝试访问web2.com时,出现“内部服务器错误”。 所以我去检查日志,似乎myblog(web2)项目设置的“DJANGO_SETTINGS_MODULE”被web1覆盖?有没有人知道如何解决这个问题?谢谢!

<code>
[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97] mod_wsgi (pid=27246): Exception occurred processing WSGI script '/var/www/myblog/myblog/wsgi.py'.

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97] Traceback (most recent call last):

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 219, in __call__

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]     self.load_middleware()

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 39, in load_middleware

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]     for middleware_path in 
settings.MIDDLEWARE_CLASSES:

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]   File "/usr/lib/python2.6/site-packages/django/utils/functional.py", line 184, in inner

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]     self._setup()

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 42, in _setup

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]     self._wrapped = Settings(settings_module)

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 95, in __init__

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))

[Thu Jan 10 00:22:38 2013] [error] [client 220.181.108.97] ImportError: Could not import settings 'myblog.settings' (Is it on sys.path?): No module named myblog.settings
~                                               
</code>

1 个答案:

答案 0 :(得分:0)

一个建议是在apache配置中创建2个虚拟主机

www.web1.com on 80

www.web2.com on 81