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:
And then the following lines after the "WSGIScriptAlias" line (at the end of your httpd.conf):
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:
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: answered 31 Oct '10, 03:01 ryans ♦♦ This doesn't work with a mod_wsgi application!
(31 Jan '11, 09:16)
khaz
Did you add the required modules to the top of your httpd.conf? 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
(31 Jan '11, 10:05)
tie
That worked to me just fine. For the ones (like me) that just copy-paste this piece of code, just remember at line "AuthUserFile" to subtitute '/path/to' with the path where .htpasswd file is. You should put the relevant path (e.g. AuthUserFile "../.htpasswd").
(02 Feb '12, 15:01)
zafm
If using Apache 2.4, change the .htaccess file from:
to:
(01 Apr '14, 12:48)
source3
Thanks
(13 Mar '15, 12:23)
mike
|
I have found that if you are using Django & mod_wsgi, you need to add the following configuration directive to your httpd.conf file:
answered 24 Feb '11, 09:51 redseam Thanks - this fixed Tasty-Pie access problems for me.
(02 Apr '13, 22:34)
kpd
This "WSGIPassAuthorization On" alone is enough to enable basic authentication for web2py. I guess it also applies to all web framework behind mod_wsgi.
(24 Jun '13, 00:37)
iceberg
Made an account just to say that THIS IS THE CORRECT ANSWER and saved me 5 hours of debugging. Thanks!
(24 Oct '15, 07:14)
caroso1222
|
You can also achieve this easily within django and login a django user. See this sample views.py:
answered 01 Nov '10, 12:19 lamusoftware Note to self - requires WSGIPassAuthorization On directive in .htaccess
(22 Nov '10, 06:57)
lamusoftware
|
thanks - I too needed to
answered 13 Mar '15, 12:22 mike |