Apache2+fastcgi動作テスト
site-enabledの修正
# vi /etc/apache2/sites-enabled/default --- DocumentRoot /var/www/ <Directory /var/www/> Options ExecCGI AllowOverride None Order allow,deny allow from all RedirectMatch ^/$ /index.fcgi </Directory> ---
index.fcgiの作成
# vi /var/www/index.fcgi --- #!/usr/bin/perl -w use FCGI; use strict; my $count = 0; my $handling_request = 0; my $exit_requested = 0; my $request = FCGI::Request(); sub sig_handler { $exit_requested = 1; exit(0) if !$handling_request; } $SIG{USR1} = \&sig_handler; $SIG{TERM} = \&sig_handler; $SIG{PIPE} = 'IGNORE'; while ($handling_request = ($request->Accept() >= 0)) { &do_request; $handling_request = 0; last if $exit_requested; } $request->Finish(); exit(0); sub do_request() { print("Content-type: text/html\r\n\r\n", ++$count); $request->Finish(); } ---
パーミッションの設定
# chmod 755 /var/www/index.fcgi
Apache2再起動
# /etc/init.d/apache2 restart
ブラウザで確認
最初に"1"が表示され、F5でリロードするたびに数字がインクリメントされれば成功
はまりポイント:
最初index.fcgiを
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "test";
としてテストしていたが、
[error] [client xxx.xxx.xxx.xxx] Premature end of script headers: index.fcgi [notice] mod_fcgid: process /var/www/index.fcgi(9515) exit(server exited), terminated by calling exit(), return code: 0
などのエラーログがでてしまって原因調査に半日以上つぶれたorz
fcgidで動かす場合特別な作法で記述しないといけないっぽい