我正在部署一个带有两个站点的 Django 1.5,每个站点都独立于另一个站点(每个站点都有自己的数据库),但这两个站点是子域:一个是new.mydomain.com
,另一个是dev.mydomain.com
. 我正在使用带有 mod_wsgi 的 Apache。
问题是:我正在正确地从 Apache 对 Django 的用户数据库进行身份验证,但是当我尝试将 Django 组与 Apache 身份验证一起使用时,我得到以下情况:
我可以登录到其中一个子域,例如new
没有问题,但如果我尝试登录到另一个 ( dev
) 我不能。Apache 说用户不在允许的组中。然后,如果我重新启动 Apache 并尝试登录dev
(以前这是不可能的),那么这里就没有问题,但现在无法使用其他子域登录new
!
总结一下:无论我使用哪个(允许的)用户,我都无法同时登录两个 sudomain。
子域的虚拟主机new
是(另一个看起来像这个改变路径):
<VirtualHost *:80>
ServerName new.mydomain.com
ServerAlias www.new.mydomain.com
ServerAdmin caumons@gmail.com
Alias /robots.txt /var/www/sites/master/EurekaStart.git/EurekaStart/robots.txt
Alias /favicon.ico /var/www/sites/master/EurekaStart.git/EurekaStart/static_collected/img/favicon.ico
Alias /static/ /var/www/sites/master/EurekaStart.git/EurekaStart/static_collected/
<Directory /var/www/sites/master/EurekaStart.git/EurekaStart/static_collected>
Order deny,allow
Allow from all
</Directory>
Alias /media/ /var/www/sites/master/EurekaStart.git/EurekaStart/media/
<Directory /var/www/sites/master/EurekaStart.git/EurekaStart/media>
Order deny,allow
Allow from all
</Directory>
WSGIDaemonProcess eureka-startups.com python-path=/var/www/sites/master/EurekaStart.git:/var/www/sites/master/EurekaStart.git/env/lib/python2.7/site-packages
WSGIProcessGroup eureka-startups.com
WSGIScriptAlias / /var/www/sites/master/EurekaStart.git/EurekaStart/wsgi.py
<Directory /var/www/sites/master/EurekaStart.git/EurekaStart>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Location "/">
AuthType Basic
AuthName "Enter your guest user & password"
Require group guest
Require valid-user
AuthBasicProvider wsgi
WSGIAuthUserScript /var/www/sites/master/EurekaStart.git/EurekaStart/wsgi.py
WSGIAuthGroupScript /var/www/sites/master/EurekaStart.git/EurekaStart/wsgi.py
</Location>
ErrorLog /var/www/sites/master/EurekaStart.git/logs/apache/error.log
TransferLog /var/www/sites/master/EurekaStart.git/logs/apache/access.log
</VirtualHost>
子域的wsgi.py
文件new
看起来像(的 wsgi 文件dev
和这个完全一样):
import os
import sys
from django.core.handlers.wsgi import WSGIHandler
# We need to add the site's root path to sys.path when using Django Authentication for WSGI
SITE_PKG_PATH = os.path.abspath(os.path.dirname(__file__))
SITE_ROOT_PATH = os.path.abspath(os.path.join(SITE_PKG_PATH, '..'))
sys.path.append(SITE_ROOT_PATH)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "EurekaStart.settings")
# This import MUST be done after setting `DJANGO_SETTINGS_MODULE`
import django.contrib.auth.handlers.modwsgi as modwsgi
def check_password(environ, user, password):
return modwsgi.check_password(environ, user, password)
def groups_for_user(environ, user):
return modwsgi.groups_for_user(environ, user)
application = WSGIHandler()
更新 1:
非常感谢@GrahamDumpleton :)
我已经更新了 apache 配置文件和我设置的方式DJANGO_SETTINGS_MODULE
。现在,关于 Apache 的 WSGI 的配置如下所示:
现场new
:
WSGIDaemonProcess eureka-startups.com python-path=/var/www/sites/master/EurekaStart.git:/var/www/sites/master/EurekaStart.git/env/lib/python2.7/site-packages
WSGIProcessGroup eureka-startups.com
<Location "/">
AuthType Basic
AuthName "Enter your guest user & password"
AuthBasicProvider wsgi
Require group guest
Require valid-user
WSGIAuthUserScript /var/www/sites/master/EurekaStart.git/EurekaStart/wsgi.py application-group=eureka-startups.com
WSGIAuthGroupScript /var/www/sites/master/EurekaStart.git/EurekaStart/wsgi.py application-group=eureka-startups.com
</Location>
现场dev
:
WSGIDaemonProcess dev.eureka-startups.com python-path=/var/www/sites/dev/EurekaStart-dev.git:/var/www/sites/dev/EurekaStart-dev.git/env/lib/python2.7/site-packages
WSGIProcessGroup dev.eureka-startups.com
<Location "/">
AuthType Basic
AuthName "Eureka-Startups staff members only"
AuthBasicProvider wsgi
Require group dev
Require valid-user
WSGIAuthUserScript /var/www/sites/dev/EurekaStart-dev.git/EurekaStart/wsgi.py application-group=dev.eureka-startups.com
WSGIAuthGroupScript /var/www/sites/dev/EurekaStart-dev.git/EurekaStart/wsgi.py application-group=dev.eureka-startups.com
</Location>