apacheで動いていた CGIを nginxに持ってくると動かない。
さて、どうするか? spawn-fcgiと fcgiwrapで動かします。
spawn-fcgiを入れる
# yum install epel-release # yum install spawn-fcgi fcgi-devel
fcgiwrapはソースから入れる
# wget http://github.com/gnosek/fcgiwrap/tarball/master # tar xzvf master # cd gnosek-fcgiwrap-gnosek-fcgiwrap-99c942c # autoreconf -i # ./configure # make # make install
spawn-fcgiの設定を書き込む
# nano /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"
WordPressがメインで入っていることもあって、wp-frontに設定を書いた
# nano /etc/nginx/wp-front
# location / {
# root /usr/share/nginx/html;
# index index.html index.htm index.php index.cgi;
# }
location ~ \.cgi$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
nginx、php-fpm、spawn-fcgiをリスタート
# rm -rf /var/cache/nginx/proxy_cache/ # service nginx restart # service php-fpm restart # service spawn-fcgi restart
CGIを動作させると、403 Forbiddenが表示される。
cgiファイルに実行権限がなかったので、「その他のユーザ」に実行権(x)を付与。
ついでに、CGI関係のファイルが Shift_JISだったら、
# nano /etc/nginx/conf.d/example.com.conf
server {
charset shift-jis;
}
