Configure lighttpd alias (mod_alias)

last updated in Categories Howto, lighttpd, Linux, UNIX

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/

Get 15% off on Linux Foundation certified SysAdmin, Progamming, Kubernetes/Containers and Open Stack certification & course. Use "SPLASH15" coupon code. Offer expires on August 27, 2018
training.linuxfoundation.org

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

8 comment

  1. 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/" )

  2. 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.

  3. Dunxd,

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

    Appreciate your post.

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

  5. In this line:

    server.modules += ( “mod_ alias” )

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

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

  7. 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?

  8. 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:firstDirsecondDirthirdDir

    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

    Have a question? Post it on our forum!