my failed projects

Nice URLs for CGIs With Lighttpd

  • You have: lighttpd and some CGI /path/to/foo.sh
  • You want: Execute the CGI under a nice URL, possibly with path arguments /myfoo/…; maybe serve a static page at the CGI root /myfoo/

lighttpd setup

Load mod_alias and mod_cgi:

1
server.modules += ( "mod_alias", "mod_cgi")

Set up CGI execution for under /myfoo/:

1
2
3
4
$HTTP["url"] =~ "^/myfoo/" {
  alias.url += ( "/myfoo" => "/path/to/foo.sh" )
  cgi.assign += ( "/path/to/foo.sh" => "" )
}

This will run /path/to/foo.sh as CGI for every access to /myfoo and below. For example, an access to /myfoo/bar/z will run /path/to/foo.sh with the environment variable PATH_INFO set to /bar/z.

Optional serving of index in the CGI root

If you want the CGI to only be executed below /myfoo/, and have an index page /path/of/index.html served for /myfoo, modify the setup to match ^/myfoo/. instead of ^/myfoo/, and add an alias to the directory of the index:

1
2
3
4
$HTTP["url"] =~ "^/myfoo/." {
...
}
alias.url += ( "/myfoo" => "/path/of" )