≡ Menu

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:

Share this tutorial on:

{ 2 comments… add one }
  • ali February 10, 2011, 2:47 pm

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

  • Niko March 14, 2013, 4:26 pm

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

Leave a Comment

   Tagged with: , , , , , , , ,