Nginx

在 Mac 上使用 nginx 和 php 找不到 info.php 文件

  • September 8, 2015

我試圖將php文件info.php放在/usr/local/www/nginx文件夾中。對於 url http://test.com/info.php,它給了我錯誤404 - Not found

我可以訪問index.htmlurl 中的文件http://test.com

我在文件中的伺服器配置nginx.conf如下。

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;
   }
}

請提出我所缺少的。謝謝。

我的error_log如下 -

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"

您發布的錯誤日誌中的最後 2 行顯示 php-fpm 沒有創建 sock-file。

請檢查您在 php-fpm 的池配置文件中是否有正確的配置,它可能如下所示:

listen = /var/run/php5-fpm.sock

php-fpm 的預設監聽器是127.0.0.1:9000.

如果您發現沒有,您可能需要以下 nginx 配置/var/run/php5-fpm.sock,或者不知道如何查找和調整池配置。

location ~ \.php$ {
   try_files      $uri = 404;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include        fastcgi_params;
}

引用自:https://serverfault.com/questions/720764