我试图把php文件info.php放在/usr/local/www/nginx文件夹中。 对于http://test.com/info.phpurl,它给了我错误404 - Not found 。
我可以访问url http://test.com index.html文件
我在nginx.conf文件中的服务器configuration如下。
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; } }
请build议我缺less的东西。 谢谢。
我的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没有创buildsock文件。
请检查php-fpm的configuration文件池中是否有正确的configuration,如下所示:
listen = /var/run/php5-fpm.sock
php-fpm的默认侦听器是127.0.0.1:9000 。
如果您发现没有/var/run/php5-fpm.sock ,您可能需要以下nginxconfiguration,要么不知道如何查找和调整池configuration。
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; }
这是你的问题:
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
这不符合您设置的文档根目录。 我不确定你在哪里find这个configuration,但已经坏了。
这应该是:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
错误日志中的倒数第二行是您的问题的最接近原因:PHP-FPM没有运行,或者它正在侦听不同的套接字。 您需要修正fastcgi_passconfiguration参数以指向正确的PHP-FPM套接字,否则请使PHP-FPM正确运行并监听configuration中指定的套接字。