[Django]-Apache mod_wsgi basic authentication for django app

5👍

You could setup basic auth for your virtual host dev.mydomain.com. Look at http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html and http://httpd.apache.org/docs/2.2/vhosts/name-based.html for more details

EDIT: Your virtual host config will look somthing like:

<VirtualHost *:80>

    ServerName mydomain.com
    DocumentRoot /srv/www/wsgi

    <Directory /srv/www/wsgi>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIScriptAlias / /srv/www/wsgi/app.wsgi

</VirtualHost>

<VirtualHost *:80>

    ServerName dev.mydomain.com
    DocumentRoot /srv/www/wsgi-dev

    <Directory /srv/www/wsgi-dev>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIScriptAlias / /srv/www/wsgi-dev/app.wsgi

    <Location />
        AuthType Basic
        AuthName "Restricted Files"
        AuthUserFile /usr/local/apache/passwd/passwords
        Require valid-user
    </Location>

</VirtualHost>

1👍

mod_wsgi doesn’t care if you use HTTP auth over it. The only provision would be that if you want it to be visible to the WSGI application then you’d need to use WSGIPassAuthorization, but this is not a concern in this case since Django has its own authentication scheme independent of HTTP auth.

Leave a comment