Configure lighttpd alias (mod_alias)

by on July 25, 2006 · 8 comments· LAST UPDATED March 8, 2008

in , ,

This lighttpd module provides for mapping different parts of the host filesystem in the document tree. You can use it for mapping various directories. For example cgi-bin directory mapped to /var/lib/cgi-bin. The alias module is used to specify a special document-root for a given url-subset.

Configuration

Open your lighttpd configuration file:
vi /etc/lighttpd/lighttpd.conf

Append/add mod_ alias to list of server modules:
server.modules += ( "mod_alias" )

Examples

Add cgi-bin alias for doamin theos.in
alias.url = ( "/cgi-bin/" => "/home/lighttpd/theos.in/cgi-bin/" )

Browse all documents installed at /usr/share/doc/ directory with following alias:
alias.url = ( "/docs/" => "/usr/share/doc/" )
alias.url += ( "/stats/" => "/home/theos.in/http/webalizer/" )

Open a browser and type url http://theos.in/docs/ or http://your-domain.com/docs/

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

{ 8 comments… read them below or add one }

1 Dunxd October 2, 2006 at 4:32 pm

Want to add more than one alias?

Use += for subsequent alias.url lines.

E.g.

alias.url = ( "/cgi-bin/" => "/home/lighttpd/theos.in/cgi-bin/" )
alias.url += ( "docs/" => "/usr/share/doc/" )

Reply

2 Dunxd October 2, 2006 at 4:36 pm

On Windows the trailing slash for the alias (the first path) breaks the configuration.

E.g.

alias.url = ( "/docs/" => "/usr/share/doc/" )
^

Doesn’t work.

alias.url = ( "/docs" => "/usr/share/doc/" )

Does work.

Reply

3 nixCraft October 2, 2006 at 6:52 pm

Dunxd,

Thanks for pointing out windows and UNIX difference while configuring alias.

Appreciate your post.

Reply

4 nixCraft October 2, 2006 at 7:00 pm

You can use += or use following syntax:
alias.url = (
"/stats/star/" => "/home/lighttpd/stats/out/",
"/docs/" => "/usr/share/docs/",
"/somedir/" => "/home/somewhere/"
)

Reply

5 Minh July 6, 2007 at 5:55 pm

In this line:

server.modules += ( “mod_ alias” )

Is the space bewteen “mod_” and “alias” intentional?

Reply

6 nixCraft July 6, 2007 at 6:17 pm

> Is the space bewteen “mod_” and “alias” intentional?
Noop, it was a typo.

Reply

7 Howard Miller March 7, 2008 at 10:59 am

It appears that when using an alias, the index.file-names setting is ignored. If, for example, you want index.php to be found then it won’t work with an alias.

Is this a bug, or am I missing something obvious?

Reply

8 Sirolway August 5, 2009 at 12:12 pm

I’m trying to configure a couple of aliases using lighttpd for Windows
The second alias is nested in a sub-sub folder of the first, so the folder structure is
c:\firstDir\secondDir\thirdDir

The application I’m trying to use references http://servername/firstDir/thirdDir
So I need to configure Lighttpd to do this…

Lighttpd won’t start if I try:

alias.url = (
“/firstDir/” => “C:/firstDir/”,
“/firstDir/thirdDir/” => “C:/firstDir/secondDir/thirdDir/”
)

Can anyone tell me how I can configure aliases that are nested inside other aliases…?
TIA

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous post:

Next post: