我有一个简单的FastCGI脚本:
public static void main (String args[]) { int count = 0; while(new FCGIInterface().FCGIaccept()>= 0) { count ++; System.out.println("Content-type: text/html\n\n"); System.out.println("<html>"); System.out.println( "<head><TITLE>FastCGI-Hello Java stdio</TITLE></head>"); System.out.println("<body>"); System.out.println("<H3>FastCGI Hello Java stdio</H3>"); System.out.println("request number " + count + " running on host " + System.getProperty("SERVER_NAME")); System.out.println("</body>"); System.out.println("</html>"); } }
设置为lighttpd为:
server.modules += ( "mod_fastcgi" ) fastcgi.debug = 1 fastcgi.server = ( "/cgi" => ( "fastcgi" => ("port" => 8888, "host" => "127.0.0.1", "bin-path" => "/var/www/tiny.fcgi", "min-procs" => 1, "max-procs" => 1, "check-local" => "disable" )) )
在日志中:
2012-11-24 04:35:04: (mod_fastcgi.c.1367) --- fastcgi spawning local proc: /var/www/tiny.fcgi port: 54321 socket max-procs: 1 2012-11-24 04:35:04: (mod_fastcgi.c.1391) --- fastcgi spawning port: 54321 socket current: 0 / 1 2012-11-24 04:35:39: (mod_fastcgi.c.3061) got proc: pid: 0 socket: tcp:127.0.0.1:54321 load: 1
问题是没有数据从服务器发送到浏览器。 我在这里错过了什么?
我认为直接来自fastcgi.com的Java FastCGI开发包有一些缺陷。 这是在2000年的最后一次修改。检查我的答案在这里 ,答案有一个补丁,我需要申请,FastCGI接口工作多个请求(奇怪你甚至没有得到一个请求通过)。 如果补丁不能在Nginx上为你工作,那么界面可能会有更多的错误。 考虑尝试一下Apache 2.4+。 您可以使用Wireshark来比较FastCGI通信并find其他错误,或者您可以使用Apache 2.4+。
尝试使用OutputStream FCGIInterface.request.outStream而不是System.out。
虽然文档声称它会将System.out设置为指向FastCGIstream,但实际上并没有这样做。 也许没有人实际使用过这个,可能会有更多的bug