FastCGIで高速化する
- Apache のバージョン確認.2.2系は2.0系にしないといけないらしい.2.0系なのでそのまま.
# httpd -v Server version: Apache/2.0.54
FastCGI インストール
# wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz # tar xvzf fcgi-2.4.0.tar.gz # cd fcgi-2.4.0 # ./configure # make # make install
- 共有ライブラリパスの確認
# ldconfig -v|grep "/usr/local/lib"
- 見つからないので,/etc/ld.so.conf に以下を追記
/usr/local/lib
- FastCGI のパスを確認
# ldconfig -v|grep "fcgi" libfcgi.so.0 -> libfcgi.so.0.0.0 libfcgi++.so.0 -> libfcgi++.so.0.0.0
FactCGIアダプタ インストール
# gem install fcgi complete Building native extensions. This could take a while... Successfully installed fcgi-0.8.7
mod_fastcgi インストール
# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz # tar xvzf mod_fastcgi-2.4.2.tar.gz # cd mod_fastcgi-2.4.2 # cp Makefile.AP2 Makefile
top_dir = /etc/httpd
- 続いてmakeする
# make # make install
- mod_fastcgi.so の確認
# ls -l /etc/httpd/modules/ | grep "fastcgi" -rwxr-xr-x 1 root root 194255 2月 22 21:35 mod_fastcgi.so
設定
LoadModule fastcgi_module modules/mod_fastcgi.so <IfModule mod_fastcgi.c> FastCgiIpcDir /var/run/fastcgi </IfModule>
AddHandler fastcgi-script .cgi AddHandler fastcgi-script .fcgi RewriteRule ^(.*)$ dispatch.cgi [QSA,L] RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
- public/dispatch.fcgi パス(1行目)の確認を一応忘れずに
#!/usr/bin/ruby
- Apache起動一発目(初期化とプロセス生成時)は今までと同じ程度に遅いけど,それ以降は劇的に高速化した.スゴい.