info.php file not found with nginx and php on Mac

abhishek asked:

I have tried to put php file info.php inside /usr/local/www/nginx folder. For url http://test.com/info.php, it’s giving me the error 404 - Not found.

I am able to access index.html file in url http://test.com

My server configuration in nginx.conf file is as follows.

server {
    listen       80;
    server_name  test.com www.test.com;
    root /usr/local/www/nginx;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page      500 502 503 504  /50x.html;
    location = /50x.html {
        root /usr/local/www/nginx-dist;
    }

    location ~ .php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            fastcgi_pass unix:/var/run/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
            include fastcgi_params;
    }
}

Please suggest what I am missing. Thanks.

My error_log is as follows –

2015/09/08 09:13:06 [notice] 8965#0: using the "kqueue" event method
2015/09/08 09:13:06 [notice] 8965#0: nginx/1.7.7
2015/09/08 09:13:06 [notice] 8965#0: built by clang 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
2015/09/08 09:13:06 [notice] 8965#0: OS: Darwin 14.4.0
2015/09/08 09:13:06 [notice] 8965#0: hw.ncpu: 4
2015/09/08 09:13:06 [notice] 8965#0: net.inet.tcp.sendspace: 131072
2015/09/08 09:13:06 [notice] 8965#0: kern.ipc.somaxconn: 128
2015/09/08 09:13:06 [notice] 8965#0: getrlimit(RLIMIT_NOFILE): 2560:9223372036854775807
2015/09/08 09:13:06 [notice] 8966#0: start worker processes
2015/09/08 09:13:06 [notice] 8966#0: start worker process 8967
2015/09/08 09:13:06 [notice] 8966#0: start worker process 8968
2015/09/08 09:13:06 [notice] 8966#0: signal 23 (SIGIO) received
2015/09/08 09:13:11 [crit] 8968#0: *1 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: test.com, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "test.com"
2015/09/08 09:13:11 [error] 8968#0: *1 open() "/usr/local/www/nginx-dist/50x.html" failed (2: No such file or directory), client: 127.0.0.1, server: test.com, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock", host: "test.com"

My answer:


Here is your problem:

            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;

This doesn’t correspond to the document root you set. I’m not sure where you found this configuration, but it’s broken.

This should read:

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.