Using Fastcgi with Apache HTTP Server 2.4
Total Page:16
File Type:pdf, Size:1020Kb
Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick The world of FastCGI Using FastCGI with Apache HTTP Server 2.4 FastCGI with Apache httpd 2.4 Jeff Trawick Choosing mod fcgid http://emptyhammock.com/ mod proxy fcgi [email protected] mod authnz fcgi Other tools April 8, 2014 PHP Applications and FastCGI Future 1/97 Revisions Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick The world of FastCGI 2014-04-10 FastCGI with Apache httpd Add Require expr ... to /www/tools/ 2.4 configuration in More classic CGI configuration Choosing slide to resolve a potential security hole. Thank mod fcgid mod proxy fcgi you Eric Covener! mod authnz fcgi Other tools PHP Applications and FastCGI Future 2/97 Get these slides... Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick The world of FastCGI FastCGI with Apache httpd 2.4 http://emptyhammock.com/projects/info/slides.html Choosing mod fcgid mod proxy fcgi mod authnz fcgi Other tools PHP Applications and FastCGI Future 3/97 Table of Contents Using FastCGI with Apache HTTP Server 1 The world of FastCGI 2.4 Jeff Trawick 2 FastCGI with Apache httpd 2.4 The world of FastCGI 3 Choosing FastCGI with Apache httpd 4 mod fcgid 2.4 Choosing 5 mod proxy fcgi mod fcgid mod proxy fcgi 6 mod authnz fcgi mod authnz fcgi Other tools 7 Other tools PHP Applications 8 PHP Applications and FastCGI and FastCGI Future 9 Future 4/97 Introduction | Who am I? Using FastCGI with Apache HTTP Server 2.4 I've worked at Jeff Trawick several large corporations, for over two decades The world of FastCGI my own one-person company, Emptyhammock, for the FastCGI with last two years Apache httpd 2.4 I've worked on Choosing several products which were primarily based on or mod fcgid otherwise included Apache HTTP Server mod proxy fcgi lower-level networking products mod authnz fcgi web applications Other tools PHP I've developed or maintained some of the FastCGI Applications and FastCGI support in the Apache HTTP Server project. Future 5/97 Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick The world of FastCGI FastCGI with Apache httpd 2.4 The world of FastCGI Choosing mod fcgid mod proxy fcgi mod authnz fcgi Other tools PHP Applications and FastCGI Future 6/97 Implemented for most web servers. Implemented for most programming languages and a number of frameworks. FastCGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick The world of FastCGI A protocol for communicating between a web server and FastCGI with persistent application processes which can handle any of Apache httpd 2.4 several different phases of requests. Choosing mod fcgid mod proxy fcgi mod authnz fcgi Other tools PHP Applications and FastCGI Future 7/97 Implemented for most programming languages and a number of frameworks. FastCGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick The world of FastCGI A protocol for communicating between a web server and FastCGI with persistent application processes which can handle any of Apache httpd 2.4 several different phases of requests. Choosing Implemented for most web servers. mod fcgid mod proxy fcgi mod authnz fcgi Other tools PHP Applications and FastCGI Future 7/97 FastCGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick The world of FastCGI A protocol for communicating between a web server and FastCGI with persistent application processes which can handle any of Apache httpd 2.4 several different phases of requests. Choosing Implemented for most web servers. mod fcgid Implemented for most programming languages and a mod proxy fcgi mod authnz fcgi number of frameworks. Other tools PHP Applications and FastCGI Future 7/97 input stream for request body output stream for response headers and body output stream for log messages But binary encoded on a stream socket or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick Inputs and outputs are similar to CGI: The world of FastCGI environment variables FastCGI with CONTENT LENGTH, SCRIPT NAME, etc. Apache httpd 2.4 Choosing mod fcgid mod proxy fcgi mod authnz fcgi Other tools PHP Applications and FastCGI Future 8/97 output stream for response headers and body output stream for log messages But binary encoded on a stream socket or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick Inputs and outputs are similar to CGI: The world of FastCGI environment variables FastCGI with CONTENT LENGTH, SCRIPT NAME, etc. Apache httpd 2.4 input stream for request body Choosing mod fcgid mod proxy fcgi mod authnz fcgi Other tools PHP Applications and FastCGI Future 8/97 output stream for log messages But binary encoded on a stream socket or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick Inputs and outputs are similar to CGI: The world of FastCGI environment variables FastCGI with CONTENT LENGTH, SCRIPT NAME, etc. Apache httpd 2.4 input stream for request body Choosing output stream for response headers and body mod fcgid mod proxy fcgi mod authnz fcgi Other tools PHP Applications and FastCGI Future 8/97 But binary encoded on a stream socket or pipe (Windows). FastCGI process waits repeatedly for new connections. Fast CGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick Inputs and outputs are similar to CGI: The world of FastCGI environment variables FastCGI with CONTENT LENGTH, SCRIPT NAME, etc. Apache httpd 2.4 input stream for request body Choosing output stream for response headers and body mod fcgid mod proxy fcgi output stream for log messages mod authnz fcgi Other tools PHP Applications and FastCGI Future 8/97 Fast CGI Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick Inputs and outputs are similar to CGI: The world of FastCGI environment variables FastCGI with CONTENT LENGTH, SCRIPT NAME, etc. Apache httpd 2.4 input stream for request body Choosing output stream for response headers and body mod fcgid mod proxy fcgi output stream for log messages mod authnz fcgi But binary encoded on a stream socket or pipe (Windows). Other tools FastCGI process waits repeatedly for new connections. PHP Applications and FastCGI Future 8/97 Raw CGI Using FastCGI with Apache HTTP Server 2.4 int main(int argc, char **argv) Jeff Trawick { The world of extern char **environ; FastCGI /* environ is {"CONTENT_LENGTH=105", FastCGI with "SCRIPT_NAME=/path/to/foo.fcgi", etc. } */ Apache httpd 2.4 const char *cl_str; Choosing mod fcgid if ((cl_str = getenv("CONTENT_LENGTH")) { read(FILENO_STDIN,,); /* request body */ mod proxy fcgi } mod authnz fcgi write(STDOUT_FILENO,,); /* response headers Other tools * and body */ PHP write(STDERR_FILENO,,); /* to web server log */ Applications and FastCGI } Future 9/97 Raw FastCGI Using FastCGI with Apache int main(int argc, char **argv) HTTP Server { 2.4 socket(); bind(); listen(); Jeff Trawick while (1) { The world of int cl = accept(); FastCGI read(cl, buf); FastCGI with |00000 0101000100080000 0001000000000000 ........ ........| Apache httpd 2.4 |00010 0104000100190000 090e485454505f48 ........ ..HTTP_H| Choosing |00020 4f53543132372e30 2e302e313a383038 OST127.0 .0.1:808| |00030 3101040001002000 000f0f485454505f 1..... ...HTTP_| mod fcgid |00040 555345525f414745 4e54417061636865 USER_AGE NTApache| mod proxy fcgi |00050 42656e63682f322e 3301040001001000 Bench/2. 3.......| mod authnz fcgi |00060 000b03485454505f 4143434550542a2f ...HTTP_ ACCEPT*/| Other tools write(cl, buf); PHP |00000 01060001041a0600 436f6e74656e742d ........ Content-| Applications and FastCGI |00010 547970653a207465 78742f706c61696e Type: te xt/plain| |00020 0a0a787878787878 7878787878787878 ..xxxxxx xxxxxxxx| Future |00030 7878787878787878 7878787878787878 xxxxxxxx xxxxxxxx| close(cl); } 10/97 } Raw FastCGI Using FastCGI with Apache HTTP Server How the datastream is defined: 2.4 Jeff Trawick version | 1 byte, always 1 The world of type | 1 byte, stuff like begin-request, abort-request, FastCGI params, stdin-data, stdout-data, etc. FastCGI with Apache httpd request id | 2 byte request identifier 2.4 Choosing content length | 2 byte length of bundled data mod fcgid padding length | 1 byte length of padding data mod proxy fcgi the data (0{64k bytes) mod authnz fcgi Other tools the padding (0{255 bytes) PHP Applications |0101000100080000 0001000000000000 ........ ........| and FastCGI |0104000100190000 090e485454505f48 ........ ..HTTP_H| Future 11/97 Programming support Using FastCGI with Apache HTTP Server 2.4 Jeff Trawick After all, nobody would want to reinvent that protocol. The world of FastCGI protocol libraries are available for use with Perl, FastCGI FastCGI with Python, Ruby, C, etc., often based on the C library from Apache httpd Open Market. 2.4 Choosing Code to the API to implement a FastCGI application. mod fcgid With some APIs, a properly coded FastCGI app will also mod proxy fcgi work as plain CGI. mod authnz fcgi PHP supports it transparently. Other tools Some frameworks support it transparently. PHP Applications and FastCGI Future 12/97 Dual-mode CGI/FastCGI Perl script: use CGI::Fast; while (my $q = CGI::Fast->new) { $mode = $q->param('mode'); print $q->header(-type => 'text/html'); print $q->start_html('hello, world'), $q->h1('hello, world'), $q->end_html; } But beware of unintentionally saved state. Perl example, moving from CGI to FastCGI Using FastCGI CGI-only Perl script: with Apache HTTP Server use CGI; 2.4 my $q = CGI->new; Jeff Trawick $mode = $q->param('mode'); print $q->header(-type => 'text/html'); The