P. 1
Docs ModFastCGI - Lighttpd - Lighty Labs

Docs ModFastCGI - Lighttpd - Lighty Labs

|Views: 5|Likes:
Published by JokoWidodo
how to
how to

More info:

Published by: JokoWidodo on Jul 15, 2014
Copyright:Traditional Copyright: All rights reserved

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/09/2015

pdf

text

original

the FastCGI Interface

Description
Options
Exampl es
X-Sendfile
Load-Balancing
FastCGI and Programming Langages
S!eleton for remote athori"er
#ro$leshooting
Docs %
the FastCGI Interface
Module: mod_fastcgi
Note
#his means &o need to inclde the line
ser'er(modles )* + ,mod-fastcgi, .
or
inclde ,conf(d/fastcgi(conf,
+0hich shold ha'e the line ser'er(modles )* + ,mod-fastcgi, . $& defalt.
in &or lighttpd(conf file( 1ithot this2 &o3ll get the error
WARNING: unknown config-key: fastcgi.server ignored!
0hen tr&ing to se lighttpd 0ith fastcgi and2 for example2 php(
Description
lighttpd pro'ides an interface to external programs that spport the
FastCGI interface( #he FastCGI Interface is defined $&
http4//000(fastcgi(com/ and is a platform-independent and ser'er-
independent interface $et0een a 0e$-application and a 0e$ser'er(
#his means that FastCGI programs that rn 0ith the 5pache
0e$ser'er 0ill rn seamlessl& 0ith lighttpd and 'ice 'ersa(
"ast#GI
Warning: 5s of php 6(7(82 the cgi $inar& is installed as
,/sr/local/$in/php-cgi, $& defalt2 instead of ,/sr/local/$in/php,(
9a!e sre to s$stitte the rele'ant parts in the docmentation
$elo0(
FastCGI remo'es a lot of the limitations of CGI programs( CGI programs ha'e the pro$lem that the& ha'e to
$e restarted $& the 0e$ser'er for e'er& re:est 0hich leads to reall& $ad performance 'ales(
FastCGI remo'es this limitation $& !eeping the process rnning and handling the re:ests $& this al0a&s
rnning process( #his remo'es the time sed for the for!+. and the o'erall startp and cleanp time 0hich
is necessar& to create and destro& a process(
1hile CGI programs commnicate to the ser'er o'er pipes2 FastCGI processes se ;nix-Domain-Soc!ets or
#CP/IP to tal! 0ith the 0e$ser'er( #his gi'es &o the second ad'antage o'er simple CGI programs4
FastCGI don3t ha'e to rn on the 0e$ser'er itself $t an&0here in the net0or!(
lighttpd ta!es it a little $it frther $& pro'iding an internal FastCGI load-$alancer 0hich can $e sed to
$alance the load o'er mltiple FastCGI Ser'ers( In contrast to other soltions onl& the FastCGI process has
to $e on the clster and not the 0hole 0e$ser'er( #hat gi'es the FastCGI process more resorces than a
e(g( load-$alancer%a&ac'e%mod_&'& soltion(
If &o compare FastCGI against an a&ac'e%mod_&'& setp &o shold note that FastCGI pro'ides
additional secrit& as the FastCGI process can $e rn nder different permissions than the 0e$ser'er and
can also li'e in a chroot 0hich might $e different than the one the 0e$ser'er is rnning in(
Options
lighttpd pro'ides the FastCGI spport 'ia the fastcgi-modle +mod-fastcgi. 0hich pro'ides 8 options in the
config-file4
fastcgi.de$ug
a 'ale $et0een < and =6686 to set the de$g-le'el in the FastCGI modle( Crrentl& onl& < and > are
sed( ;se > to ena$le some de$g otpt2 < to disa$le it(
Example4
fastcgi.debug = 1
fastcgi.ma&-e(tensions
map mltiple extensions to the same fastcgi ser'er
Example4
fastcgi.map-extensions = ( ".php3" => ".php" )
or for multiple
fastcgi.map-extensions = ( ".php3" => ".php", ".php4" => ".php" )
fastcgi.server
tell the modle 0here to send FastCGI re:ests to( E'er& file-extension can ha'e its o0n handler( Load-
Balancing is done $& specif&ing mltiple handlers for the same extension(
strctre of fastcgi(ser'er section4

( extension> =>
( ! name> => "
( # $e careful% light& does 'not' (arn &ou if it doesn)t *no( a specified option here (ma*e sure &ou ha+e no t&pos)
"host" => string> ,
"port" => integer> ,
"soc*et" => string>, # either soc*et or host,port
"bin-path" => string>, # optional
"bin-en+ironment" => arra&>, # optional
"bin-cop&-en+ironment" => arra&>, # optional
"mode" => string>, # optional
"docroot" => string> , # optional if "mode" is not "authori-er"
"chec*-local" => string>, # optional
"max-procs" => integer>, # optional - (hen omitted, default is 4
"bro*en-scriptfilename" => boolean>, # optional
"fix-root-scriptname" => boolean>, # optional, since 1.4..3 (option didn)t (or* before 1.4..3)
"disable-time" => integer>, # optional
"allo(-x-send-file" => boolean>, # optional
"*ill-signal" => integer>, # optional, default is /012345(16) (+1.4.14,)
),
( "host" => ...
)
)
)
?extension@4 is the file-extension or prefix +if started 0ith ,/,.
?name@4 optional name that sho0s p in the generated statistics of mod-stats2 sefl for
indicating 0hich $ac!end handler processed this extension +e(g( #he name ,php, 0old sho0 as
,fastcgi($ac!end(php(A,.
,host,4 is ip of the FastCGI process +no spport for hostnames right no02 see B>C>D.
,port,4 is tcp-port on the ,host, sed $& the FastCGI process
,$in-path,4 path to the local FastCGI $inar& 0hich shold $e started if no local FastCGI is rnning
,soc!et,4 path to the nix-domain soc!et
,mode,4 is the FastCGI protocol mode( Defalt is ,responder,2 also ,athori"er, mode is
implemented(
,docroot,4 is optional and is the docroot on the remote host for defalt ,responder, mode( For
,athori"er, mode it is 95ED5#OFG and it points to docroot for athori"ed re:ests( For secrit&
reasons it is recommended to !eep this docroot otside of ser'er(docment-root tree(
,chec!-local,4 is optional and ma& $e ,ena$le, +defalt. or ,disa$le,( If ena$led the ser'er first
chec!s for a file in local 3ser'er(docment-root3 tree and retrns C<C +Eot Fond. if no sch file2 and
does not fall $ac! to FastCGI( If disa$led2 the ser'er for0ards a re:est to the FastCGI interface
0ithot this chec!(
,$ro!en-scriptfilename,4 $rea!s )#RI*+_"I,-NAM- in a 0a& that PHP can extract *A+._IN"/ from
it +defalt4 disa$led.
,fix-root-scriptname,4 se this for $ac!ends 0ith extension ,/, +and chec!-local is disa$led.(
,disa$le-time,4 time to 0ait $efore a disa$led $ac!end is chec!ed again +don3t set this to < for
$ac!ends &o spa0n 0ith lighttpd2 i(e( $in-path set2 as light& 0on3t restart &or $ac!ends then.
,allo0-x-send-file,4 controls if 0-,IG.++*1-send-file2 0-)endfile and 0-)endfile2 +since >(C(7C.
headers are sed( See X-Sendfile(
If $in-path is set4
,max-procs,4 the nm$er of fastcgi processes that 0ill $e started
,$in-en'ironment,4 pt an entr& into the en'ironment of the started process
,$in-cop&-en'ironment,4 clean p the en'ironment and cop& onl& the specified entries into the fresh
en'ironment of the spa0n process
,!ill-signal,4 B& defalt lighttpd send )IG+-RM to FastCGI processes2 0hich 0ere spa0ned $&
lighttpd( 5pplications2 0hich lin! li$fcgi2 need to $e !illed 0ith )IG3)R4( #his applies to php ?6(7(>2
la-magnet and others(
Examples
9ltiple extensions for the same host4
fastcgi.ser+er = (
".php" =>
(( "host" => "1.7.8.8.1",
"port" => 18.9,
"bin-path" => ":usr:local:bin:php"
)),
".php4" =>
(( "host" => "1.7.8.8.1",
"port" => 18.9
))
)
Example 0ith prefix4
fastcgi.ser+er = (
":remote;scripts:" =>
(( "host" => "1<..19=.8.3",
"port" => <888,
"chec*-local" => "disable",
"docroot" => ":" # remote ser+er ma& use
# its o(n docroot
))
)
#he re:est ,http4//m&(example(org/remote-scripts/test(cgi, 0ill $e for0arded to fastcgi ser'er at
,>I7(>=J(<(8, and the 'ale ,/remote-scripts/test(cgi, 0ill $e sed for the )#RI*+_NAM- 'aria$le( Femote
ser'er ma& prepend it 0ith its o0n docment root( #he handling of index files is also the responsi$ilit& of
remote ser'er for this case(
In the case that the prefix is not terminated 0ith a slash2 the prefix 0ill $e handled as file and ,/test(cgi,
0old $ecome a *A+._IN"/ instead of part of )#RI*+_NAM-(
Example for ,athori"er, mode4
fastcgi.ser+er = ( ":remote;scripts:" =>
(( "host" => "18.8.8..",
"port" => <888,
"docroot" => ":path;to;pri+ate;docs",
"mode" => "authori-er"
))
)
Eote that if ,docroot, is specified then its 'ale 0ill $e sed in 1/#3M-N+_R//+ and )#RI*+_"I,-NAM-
'aria$les passed to FastCGI ser'er(
X-Sendfile
If the ,allo0-x-send-file, featre is acti'e2 &o can se the follo0ing headers to send files instead of the
generated content from the $ac!end(
5s this allo0s the $ac!end to send an& file lighttpd can read to the client2 &o shold onl& se this for
trsted $ac!ends( +5s an example4 &or $ac!end pro$a$l& can3t read the SSL !e& file2 $t lighttpd can( So
althogh light& 0oldn3t deli'er the SSL !e& file in a normal re:est and the $ac!end can3t read it2 the
$ac!end cold se X-Sendfile to get the SSL !e& file.
5 $ac!end can either4
send the ,X-Sendfile4 /a$solte/path/to/file, header +,X-LIGH##PD-send-file, is an old alias for ,X-
Sendfile,.4
lighttpd 0ill send the specified file and se the file length for the Content-Length header if it can read
the file2 other0ise it 0ill ignore the header(
send the ,X-Sendfile74 filename range, header +a'aila$le since >(C(7C.
#he filename has to $e rlencoded +inclding encoding 323 as 3K7c34 str;replace(),), )>.c),
urlencode(?path))@.
Fange has the form ,start-end, +inclsi'e end. or ,start-, +from start ntil file end.L &o mst al0a&s
specif& the range2 se ,<-, for the complete file(
Example4 A-/endfile.% :tmp:test.txt 8-4<< sends the first 6<< $&tes from :tmp:test.txt(
Go can send this header more than once 0ith different parameters +or &o can com$ine single
'ales 0ith ,2 , $et0een them.(
Here is a PHP example implementation 0hich spport resma$le do0nloads

Bphp
:: Cet)s assume that ?file contains the location of the file to do(nload
?file = ":path:to:file"@
:: 0f the D22E client needs to resume a do(nload it (ill send a D22E header called "4ange"
:: 0n case of a do(nload resume (for instance (hen using (get -c), the header (ill be li*e "b&tes=.3769=8-"
:: /ee 4FG.919 section 14.36.. http%::(((.(3.org:Erotocols:rfc.919:rfc.919-sec14.html#sec14.36..
if (isset(?;/34H34!)D22E;4IJ13)") KK preg;match():LIb&tes=!8-<",-L-:), ?;/34H34!)D22E;4IJ13)")) M
:: /et Gontent-4ange header (hich should be li*e "b&tes .3769=8-1.183=16:1.183=19"
:: 2hat is start b&te N dash N last b&te N slash N total b&te si-e
:: /ee 4FG.919 section 14.19 http%::(((.(3.org:Erotocols:rfc.919:rfc.919-sec14.html#sec14.19
?length = filesi-e(?file)@
?start = substr(?;/34H34!)D22E;4IJ13)",9,-1)@
?end = ?length - 1@
header("Gontent-4ange% b&tes ?start-?end:?length")@
:: A-/endfile. does not set the .89 status code, (e ha+e to set it manuall&
:: /ee 4FG.919 section 18...7 http%::(((.(3.org:Erotocols:rfc.919:rfc.919-sec18.html#sec18...7
header("D22E:1.1 .89 Eartial content")@
:: 2he A-/endfile. (ith resume support should be li*e ":path:to:file .3769=8-"
header("A-/endfile.% ?file ?start-")@
O else M
:: Psual A-/endfile header should be li*e ":path:to:file"
header("A-/endfile% ?file")@
O
B>
Load-Balancing
#he FastCGI plgin pro'ides atomaticall& a load-$alancing $et0een mltiple FastCGI ser'ers(
fastcgi.ser+er = ( ".php" =>
(
( "host" => "18.8.8..",
"port" => 1838
),
( "host" => "18.8.8.3",
"port" => 1838 )
)
)
#o nderstand ho0 the load-$alancing 0or!s &o can ena$le the fastcgi.de$ug option and 0ill get a similar
otpt as here4
proc% 1.7.8.8.1 1831 1 1 1 31464
proc% 1.7.8.8.1 18.= 1 1 1 3144.
proc% 1.7.8.8.1 1838 1 1 1 3144<
proc% 1.7.8.8.1 18.< 1 1 . 31447
proc% 1.7.8.8.1 18.9 1 1 . 3143=
got proc% 34 31464
release proc% 48 3143=
proc% 1.7.8.8.1 18.9 1 1 1 3143=
proc% 1.7.8.8.1 18.= 1 1 1 3144.
proc% 1.7.8.8.1 1838 1 1 1 3144<
proc% 1.7.8.8.1 1831 1 1 . 31464
proc% 1.7.8.8.1 18.< 1 1 . 31447
E'en if this for mltiple FastCGI children on the local machine the follo0ing explanation is 'alid for remote
connections too(
#he otpt sho0s4
IP2 port2 nix-soc!et +is empt& here.
is-local2 state +< - nset2 > - rnning2 ((( .
acti'e connections +load.
PID
5s &o can see the list is al0a&s sorted $& the load field(
1hene'er a ne0 connection is re:ested2 the first entr& +the one 0ith the lo0est load. is selected2 the
load is increased +got proc4 (((. and the list is sorted again(
If a FastCGI re:est is done or the connection is dropped2 the load on the FastCGI proc decreases and the
list is sorted again +release proc4 (((.
#his $eha'ior is 'er& light-0eight in code and still 'er& efficient as it !eeps the fastcgi-ser'ers e:all&
loaded e'en if the& ha'e different CP;s(
FastCGI and Programming Langages
*re&aring *.* as a "ast#GI &rogram
One of the most important application that has a FastCGI interface is php 0hich can $e do0nloaded from
http4//000(php(net/ ( Go ha'e to recompile the php from sorce to ena$le the FastCGI interface as it is
normall& not ena$led $& defalt in the distri$tions(
If &o alread& ha'e a 0or!ing installation of PHP on a 0e$ser'er execte a small script 0hich Mst contains
Bphp phpinfo()@ B>
and search for the line in that contains the configre call( Go can se it as the $ase for the compilation(
Go ha'e to remo'e all occrrences of N--0ith-apxsN2 N--0ith-apxs7N and the li!e 0hich 0old $ild PHP
0ith 5pache spport( 5dd the next three s0itches to compile PHP 0ith FastCGI spport(
? .:configure L
--enable-fastcgi L
--enable-force-cgi-redirect L
...
5fter compilation and installation chec! that &or PHP $inar& contains FastCGI spport $& calling4
? php -+
EDE 4.3.34G.-de+ (cgi-fcgi) (built% Qct 1< .883 .3%1<%17)
#he important part is the +cgi-fcgi.(
)tarting a "ast#GI-*.*
Starting 0ith 'ersion >(8(= lighttpd can spa0n the FastCGI processes locall& itself if necessar&4
fastcgi.ser+er = ( ".php" =>
(( "soc*et" => ":tmp:php-fastcgi.soc*et",
"bin-path" => ":usr:local:bin:php"
))
)
PHP pro'ides 7 special en'ironment 'aria$les 0hich control the nm$er of spa0ned 0or!ers nder the
control of a single 0atching process +PHP-FCGI-CHILDFEE. and the nm$er of re:ests 0hat a single
0or!er handles $efore it !ills itself(
fastcgi.ser+er = ( ".php" =>
(( "soc*et" => ":tmp:php-fastcgi.soc*et",
"bin-path" => ":usr:local:bin:php",
"bin-en+ironment" => (
"EDE;FG10;GD0CR43J" => "19",
"EDE;FG10;5IA;43SP3/2/" => "18888"
)
))
)
#o increase the secrit& of the started process &o shold onl& pass the necessar& en'ironment 'aria$les
to the FastCGI process(
fastcgi.ser+er = ( ".php" =>
(( "soc*et" => ":tmp:php-fastcgi.soc*et",
"bin-path" => ":usr:local:bin:php",
"bin-en+ironment" => (
"EDE;FG10;GD0CR43J" => "19",
"EDE;FG10;5IA;43SP3/2/" => "18888" ),
"bin-cop&-en+ironment" => (
"EI2D", "/D3CC", "P/34" )
))
)
#onfiguring *.*
If &o 0ant to se P5#H-IEFO and PHP-SELF in &o PHP scripts &o ha'e to configre php and lighttpd(
#he php(ini needs the option4
cgi.fix;pathinfo = 1
and the option ,$ro!en-scriptfilename, in &or fastcgi(ser'er config4
fastcgi.ser+er = ( ".php" =>
(( "soc*et" => ":tmp:php-fastcgi.soc*et",
"bin-path" => ":usr:local:bin:php",
"bin-en+ironment" => (
"EDE;FG10;GD0CR43J" => "19",
"EDE;FG10;5IA;43SP3/2/" => "18888"
),
"bin-cop&-en+ironment" => ( "EI2D", "/D3CC", "P/34" ),
"bro*en-scriptfilename" => "enable"
))
)
1h& this O the ,cgi(fix-pathinfo * <, 0old gi'e &o a 0or!ing *A+._IN"/ $t no *.*_)-,"( If &o
ena$le it2 it trns arond( #o fix the *A+._IN"/ N--ena$le-discard-pathN needs a )#RI*+_"I,-NAM-
0hich is against the CGI spec2 a $ro!en-scriptfilename( 1ith ,cgi(fix-pathinfo * >, in php(ini and ,$ro!en-
scriptfilename *@ ,ena$le,, &o get $oth(
Please note that the CGI $inar& has $een renamed to php-cgi in 6(7(82 so &o3ll pro$a$l& ha'e a path li!e
/sr/local/$in/php-cgi in &or config(
Roadsend *.* -- +'e /t'er *.*
Foadsend PHP2 freel& a'aila$le from http4//code(roadsend(com/pcc2 is an alternati'e implementation of
PHP that 0or!s 0ith lighttpd( It can rn PHP code directl& +as Pend PHP does.2 $t it can also compile PHP
code directl& to nati'e FastCGI $inaries(
5n example configration that can $e sed for interpreting (php files on &or ser'er 0ith Foadsend PHP4
fastcgi.ser+er = ( ".php" =>
( "localhost" =>
( "host" => "1.7.8.8.1",
"port" => 18.9,
"bin-path" => ":opt:roadsend:pcc:modules:fastcgi:pcc.fcgi",
)
)
)
#o deplo& a compiled application2 &o 0ill need mod-re0rite ena$led in &or lighttpd ser'er( 5ssming &or
app is named ,m&app,2 cop& the compiled app ,m&app(fcgi, and associated li$rar& ,li$m&app-(so, created
$& pcc to &or cgi-$in director&4
cp m&app.fcgi libm&app;u.so :usr:lib:cgi-bin:
1e se the mod-re0rite modle to gra$ all re:ests for PHP files in the application3s 0e$ root director&
and re-rote them to the FastCGI $inar&( 1e also allo0 for an index(php file
# ser+e index pages
url.re(rite-once = ( "T:m&app:?" => ":m&app:index.php" )
# main fastcgi entr&
?D22E!"url"" =U "T:m&app:.,L.php?" M
fastcgi.ser+er = ( ":m&app" =>
( "localhost" =>
( "bin-path" => ":+ar:(((:localhost:cgi-bin:m&app.fcgi",
"docroot" => ":+ar:(((:localhost:htdocs:m&app",
"host" => "1.7.8.8.1",
"port" => 18.9,
"chec*-local" => "disable"
)
)
)
O # D22E!url"
-(ternal )&awning
Spa0ning FastCGI processes directl& in the 0e$ser'er has some disad'antages li!e
FastCGI process can onl& rn locall&
has the same permissions as the 0e$ser'er
has the same $ase-dir as the 0e$ser'er
5s soon as &o are sing a separate FastCGI Ser'er to ta!e off some load from the 0e$ser'er &o ha'e to
control the FastCGI process $& a external program li!e ,spa0n-fcgi,(
,spa0n-fcgi, is sed to start a FastCGI process in its o0n en'ironment and set the ser-id2 grop-id and
change to another root-director& +chroot.(
For con'enience a 0rapper script shold $e sed 0hich ta!es care of all the necessar& option( Sch a script
in inclded in the lighttpd distri$tion and is call spa0n-php(sh(
#he script has a set of config 'aria$les &o shold ta!e a loo! at4
## I$/QCP23 path to the spa(n-fcgi binar&
/EIVJFG10=":usr:local:sbin:spa(n-fcgi"
## I$/QCP23 path to the EDE binar&
FG10E4Q14I5=":usr:local:bin:php"
## bind to tcp-port on localhost
FG10EQ42="18.9"
## bind to unix domain soc*et
# FG10/QGW32=":tmp:php.soc*"
## number of EDE childs to spa(n
EDE;FG10;GD0CR43J=18
## number of reXuest ser+er b& a single php-process until
## is (ill be restarted
EDE;FG10;5IA;43SP3/2/=1888
## 0E adresses (here EDE should access ser+er connections
## from
FG10;V3$;/34H34;IRR4/="1.7.8.8.1,1<..19=.8.1"
# allo(ed en+ironment +ariables separated b& spaces
ICCQV3R;3JH="Q4IGC3;DQ53 EI2D P/34"
## if this script is run as root s(itch to the follo(ing user
P/340R=(((run
14QPE0R=(((run
exec ?/EIVJFG10 -a ?FG10;V3$;/34H34;IRR4/ -p ?FG10EQ42 -f ?FG10E4Q14I5 -u ?P/340R -g ?14QPE0R
If &o ha'e set the 'aria$les to 'ales that fit to &or setp &o can start it $& calling4
? spa(n-php.sh
spa(n-fcgi.c.139% child spa(ned successfull&% E0R% 9<.6
If &o get ,child spa0ned sccessfll&4 PID4, the php processes cold $e started sccessfll&( Go shold
see them in &or process list4
? ps ax N grep php
9<.6 B / 8%88 :usr:local:bin:php
9<.= B / 8%88 :usr:local:bin:php
...
#he nm$er of processes shold $e *.*_"#GI_#.I,1R-N ) >( Here the process =I76 is the master of
the sla'es 0hich handle the 0or! in parallel( Em$er of parallel 0or!ers can $e set $&
*.*_"#GI_#.I,1R-N( 5 0or!er dies atomaticl& of handling *.*_"#GI_MA0_R-53-)+) re:ests as
PHP might ha'e memor& lea!s(
If &o start the script as ser root php processes 0ill $e rnning as the ser 3)-RI1 and grop GR/3*I1
to drop the root permissions( Other0ise the php processes 0ill rn as the ser &o started script as(
5s the script might $e started from a n!no0n stage or e'en directl& from the command-line it cleans the
en'ironment $efore starting the processes( A,,/W-1_-N6 contains all the external en'ironement
'aria$les that shold $e a'aila$le to the php-process(
5 patch for ,spa0n-fcgi, so that it can accept a cstom configration file location can $e fond here4
http4//form(lighttpd(net/topic/CC=B>7IC
#he patch mst $e applied in the sorce director& of lighttpd3s sorce code( #he file to patch is ,spa0n-
fcgi(c, and re:ires a recompile of light& to ha'e the $inar& compiled 0ith it as 0ell(
It is re:ired to add the follo0ing in the ,spa0n-php(sh, file4
## I$/QCP23 path to EDE config
FG10;GQJF01=":path:to:php:config:php6.ini"
5fter4
## I$/QCP23 path to the EDE binar&
FG10E4Q14I5=":etc:lighttpd:php"
5nd change the similar lines at the $ottom of the file to4
if test x?P0R = x8@ then
3A="?/EIVJFG10 -p ?FG10EQ42 -f ?FG10E4Q14I5 -u ?P/340R -g ?14QPE0R -G ?EDE;FG10;GD0CR43J -x ?FG10;GQJF01"
else
3A="?/EIVJFG10 -p ?FG10EQ42 -f ?FG10E4Q14I5 -G ?EDE;FG10;GD0CR43J -x ?FG10;GQJF01"
fi
*erl
For Perl &o ha'e to install the FCGI modle from CP5E(
S!eleton for remote athori"er
#he $asic fnctionalit& of athori"er is as follo0s +see http4//000(fastcgi(com/de'!it/doc/fcgi-spec(html2
=(8 for details.(
#include fcgi;stdio.h>
#include stdlib.h>
#include unistd.h>
int main () M
char' p@
(hile (FG10;Iccept() >= 8) M
:' (ait for fastcgi authori-er reXuest ':
printf("Gontent-t&pe% text:htmlLrLn")@
if ((p = geten+("SP34Y;/240J1")) == JPCC) NN
SP34Y;/240J1 is unauthori-ed>)
printf("/tatus% 483 ForbiddenLrLnLrLn")@
else printf("LrLn")@
:' default /tatus is .88 - allo( access ':
O
return 8@
O
It is possi$le to se an& other 'aria$les pro'ided $& FastCGI interface for athori"ation chec!( Here is onl&
an example(
#ro$leshooting
fastcgi.de$ug shold $e ena$led for tro$leshooting(
If &o get4
(fcgi.c..74) connect dela&ed% =
(fcgi.c..=<) connect succeeded% =
(fcgi.c.746) unexpected end-of-file (perhaps the fastcgi
process died)% =
the fastcgi process accepted the connection $t closed it right a0a&( #his happens if
"#GI_W-7_)-R6-R_A11R) doesn3t inclde the host 0here &o are connection from(
If &o get4
(fcgi.c..74) connect dela&ed% 7
(fcgi.c.1187) error% unexpected close of fastcgi connection
for :peterp:seite1.php (no fastcgi process on host:port B)
(fcgi.c.1816) emergenc& exit% fastcgi% connection-fd% 6
fcgi-fd% 7
the fastcgi process is not rnning on the host/port &o are connection to( Chec! &or configration(
If &o get 44
(fcgi.c..74) connect dela&ed% 7
(fcgi.c..=<) connect succeeded% 7
e'er&thing is fine( #he connect+. call Mst 0as dela&ed a little $it and is completel& normal(
#'rooted lig'tt&d8 ev'ost and non-c'rooted fastcgi
If &o3re tr&ing to se non-chrooted fastcgi com$ined 0ith e'host in a chrooted lighttpd2 &o seem to $e
ot of lc!( #o properl& spport this configration2 lighttpd 0old need to prepend its chroot path $efore its
docment root 0hen ma!ing fastcgi re:ests( #he ,docroot, option can do this staticall& +ie2 0hen not
sing e'host.2 $t not for mltiple hosts( 5lso see B>J>= a$ot this(
Docs49odProx&Core 0ill $e spporting this configration in lighttpd >(6(
#9#%% "ast#GI on lig'tty named socket
Femem$er that named soc!ets loo!p operations are performed throgh a /proc entr& in Linx so that &o
need to mont the proc-de'ice inside an& chrooted 0e$ser'er 0here &o 0ish to se named soc!ets2 in
other operation s&stems also the re:ired /de' entries are needed +most chrooted installations 0ill re:ire
a /de'/nll atleast.( #he lightt& mod-fastcgi(c 0ill pre-open an application ser'er soc!et on file descriptor <
+loo! for FCGI-LIS#EESOCQ-FILEEO in ,fastcgi(h,. alread& going throgh the soc!et+./$ind+./listen+. c&cle
for 5F-;EIX soc!ets - so in &or FastCGI program &o onl& need to rn accept+.( For the mltithreaded case
&o need to rn FCGX-Init one time and to create as man& FCGX-Fe:est handles as &o 0ish(
:: gcc -0:usr:include:fastcgi -lfcgi testfastcgi.c -o test.fastcgi
#include stdlib.h>
#include string.h>
#include s&slog.h>
#include alloca.h>
#include fcgiapp.h>
#define C0/23J/QGW;F0C3JQ 8
#define C0/23J/QGW;FCI1/ 8
int main(int argc, char'' arg+) M
openlog("testfastcgi", CQ1;GQJ/NCQ1;JR3CIY, CQ1;P/34)@
int err = FG1A;0nit()@ :' call before Iccept in multithreaded apps ':
if (err) M s&slog (CQ1;0JFQ, "FG1A;0nit failed% >d", err)@ return 1@ O
FG1A;4eXuest cgi@
err = FG1A;0nit4eXuest(Kcgi, C0/23J/QGW;F0C3JQ, C0/23J/QGW;FCI1/)@
if (err) M s&slog(CQ1;0JFQ, "FG1A;0nit4eXuest failed% >d", err)@ return .@ O
(hile (1) M
err = FG1A;Iccept;r(Kcgi)@
if (err) M s&slog(CQ1;0JFQ, "FG1A;Iccept;r stopped% >d", err)@ brea*@ O
char'' en+p@
int si-e = .88@
for (en+p = cgi.en+p@ 'en+p@ ,,en+p) si-e ,= strlen('en+p) , 11@
char' result = (char') alloca(si-e)@
strcp&(result, "/tatus% .88 QWLrLnGontent-2&pe% text:htmlLrLnLrLn")@
strcat(result, "html>head>title>testcgi:title>:head>bod&>ul>LrLn")@
for (en+p = cgi.en+p@ 'en+p@ ,,en+p) M
strcat(result, "li>")@
strcat(result, 'en+p)@
strcat(result, ":li>LrLn")@
O
strcat(result, ":ul>:bod&>:html>LrLn")@
FG1A;Eut/tr(result, strlen(result), cgi.out)@
O
return 8@
O
and the configration record
fastcgi.ser+er = (
":login" => (
"test.fastcgi.handler" => (
"soc*et" => soc*et;dir , "test.fastcgi.soc*et",
"chec*-local" => "disable",
"bin-path" => ":usr:bin:test.fastcgi",
"max-procs" => 38,
)
)
)
*yt'on "ast#GI on lig'ty wit' flu&
Do0nload flp http4//trac(saddi(com/flp
Configre4
fastcgi.ser+er = (
".p&" =>
(
"p&thon-fcgi" =>
(
"soc*et" => soc*et;dir , "fastcgi.p&thon.soc*et",
"bin-path" => "test.p&",
"chec*-local" => "disable",
"max-procs" => 1,
)
))
test(p&4
#Z:usr:bin:p&thon..6
def m&app(en+iron, start;response)%
start;response().88 QW), !()Gontent-2&pe), )text:plain))")
return !)Dello VorldZLn)"
if ;;name;; == );;main;;)%
from flup.ser+er.fcgi import V/10/er+er
V/10/er+er(m&app).run()

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->