Project

General

Profile

Howto CGI » History » Revision 2

Revision 1 (stbuehler, 2009-11-12 22:55) → Revision 2/3 (stbuehler, 2012-08-11 10:42)

h1. Howto CGI 

 lighttpd 2.0 doesn't support running cgi scripts/binaries directly (it is a "non-forking" webserver); so you need a FastCGI wrapper around your CGI applications (sometimes you just don't want or can't convert them to real FastCGI applicatons). 
 One wrapper for this is http://cgit.stbuehler.de/gitosis/fcgi-cgi/. 

 h2. Lighttpd config 

 Just forward cgi requests to your FastCGI wrapper: 

 <pre> 
 setup { 
	 module.load ( "mod_fastcgi" ); 
 } 

 alias ("/cgi-bin/" => "/usr/lib/cgi-bin"); 

 if req.path =^ "/cgi-bin" { 
	 index ( "index.cgi", "index.pl", "index.html" ); 
	 if phys.path =~ "\.(cgi|pl)$" { 
		 if phys.is_file { 
			 fastcgi "unix:/var/run/lighttpd/sockets/www-cgi.sock"; 
		 } 
	 } 
 } 
 </pre> 

 h2. Spawn the FastCGI CGI wrapper 

 Simple ./run script to spawn rails applications with [[spawn-fcgi:WikiStart|spawn-fcgi]] and runit/daemontools: 
 <pre> 
 #!/bin/sh 

 exec 2>&1 

 exec /usr/bin/spawn-fcgi -n -s /var/run/lighttpd/sockets/www-cgi.sock -u nobody -U www-data -- /usr/bin/fcgi-cgi 
 </pre>