Lighttpd Deny Access To Folders / Directories

by on October 18, 2010 · 2 comments· LAST UPDATED October 18, 2010

in

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:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 2 comments… read them below or add one }

1 ali February 10, 2011 at 2:47 pm

But is there a way to do it in a dynamic way? Like in .htaccess file?

Reply

2 Niko March 14, 2013 at 4:26 pm

Is there a way to write several folders in the single line? Like “^/dir1/” + “^/dir2/cache/”

Reply

Leave a Comment

Tagged as: , , , , , , , ,

Previous Faq:

Next Faq: