2011-02-16 67 views
0

我有一個網站,只有註冊用戶可以登錄和查看文檔,現在這些文檔通過Apache提供,如果您有URL,可以直接查看而無需登錄。我想使用Django身份驗證來保護這些文件夾,我有蜜蜂嘗試這樣做,但沒有成功:Django保護訪問靜態媒體

的httpd.conf:

WSGIScriptAlias//home/www/wsgi-scripts/mysite.wsgi 

<Directory /home/www/wsgi-scripts> 
Order allow,deny 
Allow from all 
</Directory> 

<Location /media/protected> 
AuthType Basic 
AuthName "Authentication Required" 
AuthBasicProvider wsgi 
WSGIAuthUserScript /home/www/wsgi-scripts/auth.wsgi 
Require valid-user 
</Location> 

auth.wsgi:

import os, sys 
os.environ['PYTHON_EGG_CACHE'] = '/tmp' 
apache_configuration= os.path.dirname(__file__) 
project = os.path.dirname(apache_configuration) 
workspace = os.path.dirname(project) 
sys.path.append(workspace) 
sys.path.append('/usr/lib/python2.4/site-packages/django/') 
sys.path.append('/home/www') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' 

from django.contrib.auth.models import User 
from django import db 
import threading 
cache = threading.local() 

def check_password(environ, username, password): 
    cache.username = None 
    cache.permissions = [''] 
    db.reset_queries() 
    kwargs = {'username': username, 'is_active': True} 
    try: 
     try: 
      user = User.objects.get(**kwargs) 
     except User.DoesNotExist: 
      return None 
     if user.check_password(password): 
      cache.username = username 
      cache.permissions = user.get_group_permissions() 
      return True 
     else: 
      return False 
    finally: 
     db.connection.close() 

什麼我做錯了嗎?

THKS

回答

0

如果在Apache錯誤日誌文件中有什麼錯誤消息?

另外,什麼'mod_auth *'模塊加載到您的Apache? 。

即下面的什麼被加載:

LoadModule authn_file_module libexec/apache2/mod_authn_file.so 
LoadModule authn_dbm_module libexec/apache2/mod_authn_dbm.so 
LoadModule authn_anon_module libexec/apache2/mod_authn_anon.so 
LoadModule authn_dbd_module libexec/apache2/mod_authn_dbd.so 
LoadModule authn_default_module libexec/apache2/mod_authn_default.so 
LoadModule authz_host_module libexec/apache2/mod_authz_host.so 
LoadModule authz_groupfile_module libexec/apache2/mod_authz_groupfile.so 
LoadModule authz_user_module libexec/apache2/mod_authz_user.so 
LoadModule authz_dbm_module libexec/apache2/mod_authz_dbm.so 
LoadModule authz_owner_module libexec/apache2/mod_authz_owner.so 
LoadModule authz_default_module libexec/apache2/mod_authz_default.so 
LoadModule auth_basic_module libexec/apache2/mod_auth_basic.so 
LoadModule auth_digest_module libexec/apache2/mod_auth_digest.so 

這些中的某些子集,需要爲它工作。以上列表適用於Apache 2.2。我無法記住我的頭頂是必需的,但更新問題與你現在正在加載。