最近のサーバ環境ではRubyやPHPなどを使うことが大半だと思いますが、今でもフリーの掲示板cgiを設置するなどの用途でCGIを動作させたい時があります。
Apacheでは問題なく動かせるのですが、Nginxだと幾つかの準備が必要になります。
yum install epel-release yum install spawn-fcgi fcgi-devel wget http://github.com/gnosek/fcgiwrap/tarball/master tar xzvf master cd gnosek-fcgiwrap-gnosek-fcgiwrap-*** autoreconf -i ./configure make make install
必要なインストールが終わったので、次にspawn-fcgiの設定です。
vi /etc/sysconfig/spawn-fcgi OPTIONS="-u nginx -g nginx -a 127.0.0.1 -p 9001 -P /var/run/spawn-fcgi.pid -- /usr/local/sbin/fcgiwrap"
Nginxの設定は以下の通りです。
server {
charset shift-jis;
...
location / {
...
index index.html index.htm index.php index.cgi;
}
location ~ \.cgi$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
cgiで動く掲示板などはshift-jis設定の物が多く、Nginxだとhead内に<meta http-equiv=”Content-Type” content=”text/html;charset=Shift_JIS”>を入れていても文字化けしてしまいますし、PHPのようにini_set()も使えないので(Perlはよく知りません)、charset shift-jis;を追加しています。location内だけでも使える様なのですがcharsetの効き方が微妙なので、cgiサイトにバーチャルホストを割り当てて運用しています。





コメント