使用HTTP身份验证在Apache + mod_wsgi上部署Django应用程序

时间:2011-12-07 15:25:39

标签: django apache mod-wsgi

是否可以在Apache + mod_wsgi(the standard way)上部署Django应用程序,但在整个事情面前使用HTTP身份验证?

基本上,在任何Django认证或匿名用户甚至能够访问该应用之前,我需要额外的HTTP安全层。

这可能吗?如果是这样,Apache auth指令在哪里?

2 个答案:

答案 0 :(得分:2)

是的,这是可能的。

使用/上的mod_wsgi,apache提供的任何资源都需要列为别名。

Auth指令和主机限制存在于Location指令中。

所以我已经禁用了对css之类的任何apache访问限制,并提供了对另一个目录的基于主机/ ip的访问。

<VirtualHost *:80>
        Servername              app.domain.example
        CustomLog               logs/access_log combined
        ErrorLog                logs/error_log
        DocumentRoot            "/home/app/apache/app/html"

        Alias /media/           /home/app/apache/app/html/media/

        <Location />
                Options None
                AuthType                Basic
                AuthName                "Login Prompt"
                AuthUserFile            /path/to/passwd.file
                Require                 valid-user
        </Location>

        <Location /media>
                Order allow,deny
                Allow from all
                Satisfy any
        </Location>

        WSGIDaemonProcess       app user=app group=app processes=5 threads=1 display-name=app_WSGI
        WSGIProcessGroup        app
        WSGIScriptAlias         /       /home/app/apache/app.wsgi
</VirtualHost>

答案 1 :(得分:2)

当然,这是一个网站的例子:

<VirtualHost *:80>
  ServerName djangoproject.domain.biz

  DocumentRoot "/home/user/websites/djangoproject/website/"

  WSGIDaemonProcess djangoproject python-path=/home/user/.virtualenvs/djangoproject/lib/python2
.6/site-packages/ user=user group=user threads=1
  WSGIProcessGroup  djangoproject
  WSGIScriptAlias / /home/user/websites/djangoproject/website/django.wsgi

  <Directory "/home/user/websites/djangoproject/website/">
    Order deny,allow
    Allow from all

    AuthType Basic
    AuthName "By Invitation Only"
    AuthUserFile /etc/apache2/passwords
    Require valid-user
  </Directory>

</VirtualHost>
相关问题