LoginSignup
10
9

More than 5 years have passed since last update.

nginx + php5-fpm で、php が動いた設定ファイル例

Last updated at Posted at 2014-06-16

php が起動できずにかなりハマってしまい内外の各種ブログを参考にさせていただき、やっと以下の設定ファイルで php が動きました(<?php phpinfo();?> が、表示された)

ハマっている最中、実際に php が動いた設定のサンプルとかあれば... と思いつつも見つからなかったので、同じようにハマっている方の参考になればと思い投稿しました

/etc/nginx.conf

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
        #listen 80;
        root /usr/share/nginx/www;
        #index index.php index.html index.htm;

        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www/$fastcgi_script_name;
            include fastcgi_params;
        }
    }
}
/etc/nginx/conf.c/default.conf

server {
#listen 80;
  location / {
     root   /usr/share/nginx/www;
     index  index.html index.htm;
     index  index.php;
  }

 #location ~ \.php$ {
 #    root           html;
 #    fastcgi_pass   127.0.0.1:9000;
 #    fastcgi_index  index.php;
 #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 #    include        fastcgi_params;
 #}
 location ~ \.php$ {
     root           /usr/share/nginx/www;
     fastcgi_pass unix:/var/run/php5-fpm.sock;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/www$fastcgi_script_name;
     include        fastcgi_params;
 }
}

ポイントは多分以下のように思います
1. rastcgi_pass を unix ソケットをフルパスで記載
2. fastcgi_param で、$document を使わないでフルパスで記載

尚、当方のドキュメントルートはデフォルトの /usr/share/nginx/www のままです

あと、上記設定では nginx 起動時にまだワーニングが残ってます

pi@raspberrypi ~ $ sudo service nginx restart
Restarting nginx: nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored
nginx.
pi@raspberrypi ~ $ 
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9