Lighttpd deny access to certain files

by nixcraft on July 12, 2006 · 5 comments

Lighttpd logo

Generally, I update web pages over ssh session. The problem is that vim creates a backup files ended with a diacritical mark (~).

Some other open source software use .inc extensions of php and other include for code. However, lighttpd comes with nifty module called mod_access module which is used to deny access to files with given trailing path names.

Open lighty's config file:
# vi /etc/lighttpd/lighttpd.conf

Append or add mod_access (if it is not added) :
server.modules += ( "mod_access" )

Next append rule that deny access to files with given trailing path names (~ and .inc):
url.access-deny = ( "~", ".inc" )

Save and close the file. Restart lighttpd:
# /etc/init.d/lighttpd restart

Now if end users try to open .inc or other trailing path names he/she will get error 404.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 5 comments… read them below or add one }

1 jain July 24, 2007

Hey thanks dude

this tutorial really helps me a lot.

Reply

2 Phil July 3, 2009

If you want to block access to an entire directory and its sub directories you can do

$HTTP["url"] =~ “^/directorynamehere/” {
url.access-deny = ( “” )
}

Reply

3 Mike March 27, 2010

How do I deny files starting with a certain expression (e.g. dotfiles) ?

Reply

4 Anonymous May 28, 2010

This worked for me :

$HTTP["url"] =~ “/.” {
url.access-deny = ( “” )
}

Reply

5 Nevar May 28, 2010

This worked for me :

$HTTP["url"] =~ “/.” {
url.access-deny = ( “” )
}

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 7 + 14 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: