Configure lighttpd alias (mod_alias)

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.

ADVERTISEMENTS

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 the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
8 comments… add one
  • Dunxd Oct 2, 2006 @ 16:32

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

  • Dunxd Oct 2, 2006 @ 16:36

    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.

  • 🐧 nixCraft Oct 2, 2006 @ 18:52

    Dunxd,

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

    Appreciate your post.

  • 🐧 nixCraft Oct 2, 2006 @ 19:00

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

  • Minh Jul 6, 2007 @ 17:55

    In this line:

    server.modules += ( “mod_ alias” )

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

  • 🐧 nixCraft Jul 6, 2007 @ 18:17

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

  • Howard Miller Mar 7, 2008 @ 10:59

    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?

  • Sirolway Aug 5, 2009 @ 12:12

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.