Edit /etc/lighttpd/lighttpd.conf
nano /etc/lighttpd/lighttpd.conf
Add "mod_auth" to server.modules section. It should look like...
server.modules = (
"mod_access",
"mod_fastcgi",
"mod_alias",
"mod_compress",
"mod_auth",
Then to the end of the lighttpd.conf add
$HTTP["url"] =~ "^/DIRECTORY_YOU_WANT_TO_PROTECT/" {
auth.debug = 2
auth.backend = "plain"
auth.backend.plain.userfile = "/home/PASSWORD_FILE.pass"
auth.require = ( "/DIRECTORY_YOU_WANT_TO_PROTECT/" =>
(
"method" => "basic",
"realm" => "Password protected area",
"require" => "user=aspedisca"
)
)
You should create a password file at the location you entered above. This file should include a line saying.
username:secretepassword
Change acording to your needs.You may add more than one user though. Make sure that the password file can be read by lighttpd.
chown lighttpd:lighttpd /home/PASSWORD_FILE.pass
Also change the part saying "/DIRECTORY_YOU_WANT_TO_PROTECT/". It should be relative to your www directory.
Finally, restart lighttpd server:
/etc/init.d/lighttpd restart
Test to reach your directory by using your beloved web browser and see if it works..
Hello,
ReplyDeleteNice tutorial, thanks.
Can you tell how to password protect another folder? The above description is for one folder, I would like to know how to do it for second, third.... folder?
Thanks
Thnaks you,
ReplyDeleteWell you can do the same thing for another folder.
Add the other folder to the end of the lighttpd.conf then create a password file at the location you entered.
Hope this helps.
very nice trick..
ReplyDeletehow can i rename "Locker" folder name?
missing "}" in the end of config.
ReplyDeleteThank you