Project

General

Profile

Mod cgi » History » Revision 20

Revision 19 (gstrauss, 2016-09-11 01:10) → Revision 20/32 (gstrauss, 2017-02-02 23:06)

h1. The CGI-Module 

 *Module: mod_cgi* 

 {{>toc}} 


 h2. Description 

 CGI programs allow you to enhance the functionality of the server in a very straight-forward and simple way. 

 Note that to see stderr output from CGI processes, you need to set 

 <pre> 
     server.breakagelog = "/var/log/lighttpd/breakage.log" 
 </pre> 

 or similar. 

 h2. Options 

 *cgi.execute-x-only* 

 requires +x for cgi scripts if enabled. 


 *cgi.assign* 

 file-extensions that are handled by a CGI program 

 <pre> 
     cgi.assign = ( ".pl"    => "/usr/bin/perl", 
                    ".cgi" => "/usr/bin/perl" ) 
 </pre> 

 For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini. 

 To get the old cgi-bin behavior of apache: 

 <pre> 
     #Note: make sure that mod_alias is loaded if you use this: 
     alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" ) 
     $HTTP["url"] =~ "^/cgi-bin" { 
         cgi.assign = ( "" => "" ) 
     } 
 </pre> 

 *cgi.x-sendfile* (since 1.4.40) 
 If the "x-sendfile" feature is active, an *X-Sendfile* response header containing a fully-qualified path will cause lighttpd to send the local file found at that path instead of the generated content from the backend.    See mod_fastcgi [[lighttpd:Docs_ModFastCGI#X-Sendfile|X-Sendfile]] 
 <pre> 
     cgi.x-sendfile = "enable"    # default "disable" 
 </pre> 

 *cgi.x-sendfile-docroot* (since 1.4.40) 
 "x-sendfile-docroot" limits the directory trees allowed in the path provided by X-Sendfile response header.    See mod_fastcgi [[lighttpd:Docs_ModFastCGI#X-Sendfile|X-Sendfile]] 
 <pre> 
     cgi.x-sendfile-docroot = ( "/srv/www/html", "/srv/www/static" ) 
 </pre> 

 *cgi.execute-all* (1.5 (abandoned)    Note: 1.5.0 release branch no longer maintained) 

 <pre> 
     $PHYSICAL["existing-path"] =~ "^/var/www/myvhost/cgi-bin/" { 
       cgi.execute-all = "enable" 
     } 
 </pre> 

  which does the same thing as cgi.assign = ("" => "") but is more obvious to use. 
 
 h2. Examples 

 To setup an executable which can run on its own (e.g. binaries, scripts with a shebang line) you just don't specify a handler for the extension: 

 <pre> 
   cgi.assign = ( ".sh" => "" ) 
 </pre> 
  
 If the file has no extension keep in mind that lighttpd matches not the extension itself but the right part of the URL: 

 <pre> 
   cgi.assign = ( "/testfile" => "" ) 
 </pre> 

 To assign a CGI script to handle a URL path, even if that path is virtual, with the help of mod_alias: 

 <pre> 
 $HTTP["url"] =~ "^/urlpath(?:/|$)" { 
   alias.url = ( "/urlpath" => "/path/to/script" ) 
   cgi.assign = ( "" => "" ) 
 } 
 </pre>