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:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 2 comments… read them below or add one }
But is there a way to do it in a dynamic way? Like in .htaccess file?
Is there a way to write several folders in the single line? Like “^/dir1/” + “^/dir2/cache/”