This is accomplished by editing the httpd.conf for the Apache server that runs your mod_wsgi/Django application. First, add the following lines of code near the top of your mod_wsgi/Django application's httpd.conf file:
| LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_user_module modules/mod_authz_user.so
|
And then the following lines after the "WSGIScriptAlias" line (at the end of your httpd.conf):
| <Location />
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/path/to/.htpasswd"
Require valid-user
</Location>
|
It is necessary to restart the Apache instance in order for these changes to take effect.
Note: You can protect a sub-path of an application (for example, /members) using:
| <Location /members>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/path/to/.htpasswd"
Require valid-user
</Location>
|
Lastly, the 'htpasswd' command is used to create the .htpasswd file referenced above. More information on .htpasswd files (and other features of Apache Basic Authentication) can be found in the related guide for Static/CGI/PHP applications:
http://docs.webfaction.com/software/static.html#password-protecting-a-directory-with-a-static-cgi-php-app
answered
Oct 31 '10 at 03:01
ryans ♦♦
2841●1●4●20