Monday, April 23, 2012

Lighttpd Deny Access To Folders / Directories

If users try to open a Web page (http://example.com/dir1/file.php); I'd like to display a "URL Access Denied" message for /dir1/, /www/, and /dir2/cache/ directories under lighttpd web server? How do I configure lighttpd to deny access to directory?

The mod_access module is used to deny access to files and directories. Edit /etc/lighttpd/lighttpd.conf file as follows:
# vi lighttpd.conf
Add the following code to enable mod_access:
server.modules += ( "mod_access" )
Finally add regex as follows:
 
# deny access to /dir1
$HTTP["url"] =~ "^/dir1/" {
url.access-deny = ("")
}
# deny access to /dir2/cache/
$HTTP["url"] =~ "^/dir2/cache/" {
url.access-deny = ("")
}
# add other config below
 
Save and close the file. Restart the lighttpd web server (first, check for syntax error):
# lighttpd -t -f /etc/lighttpd/lighttpd.conf
# service lighttpd restart

See also:

  • Lighttpd restrict or deny access by IP address

No comments:

Post a Comment