1

我正在尝试在我的 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>
4

1 回答 1

0

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

www.web1.com on 80

www.web2.com on 81
于 2013-01-10T10:31:19.710 回答