2012年12月17日月曜日

nginxでphpを動かしてみる。

どうも忘れっぽくて。
色々なところで書かれてたりとブクマとか色々探すの('A`)マンドクセ

phpはインストールしてあるとして
とりあえずnginx

# pkg install nginx
# echo 'nginx_enable="YES"' >> /etc/rc.conf
# cp /usr/local/etc/nginx/nginx.conf-dist /usr/local/etc/nginx/nginx.conf

次にspawn-fcgi
spawn-fcgiでなくても出来るらしいけど面倒なのは嫌いです('A`)

# pkg install spawn-fcgi
# 'spawn_fcgi_enable="YES"' >> /etc/rc.conf

そしてnginx.confのここと


-            index  index.html index.htm;
+            index  index.html index.htm index.php;

ここ。

-#location ~ \.php$ {
+location ~ \.php$ {
-        #    root           html;
+            root           html;
-        #    fastcgi_pass   127.0.0.1:9000;
+            fastcgi_pass   127.0.0.1:9000;
-        #    fastcgi_index  index.php;
+            fastcgi_index  index.php;
-        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
+            fastcgi_param  SCRIPT_FILENAME  /usr/local/www/nginx$fastcgi_script_name;
-        #    include        fastcgi_params;
+            include        fastcgi_params;
-        #}
+        #}


#を取り外して変更するだけの簡単な作業ですね。

# /usr/local/etc/rc.d/nginx start

うちの環境だと面倒なしに動いてるので良しなのです。
configの中身も(あれと比べると)スッキリでbasic認証とかも突っ込み易くて良いですね。