nginx和php-fpm不能通信,网上各种办法都试过,就是不行,后来换了一下root的位置就解决了!
出现这个原因有三:

1、文件不存在

2、php-fpm 与nginx不能通信

3、root位置错误

文件位置:​​/etc/nginx/conf.d​

server {
listen 80;
server_name localhost;

access_log /var/log/nginx/log/host.access.log main;
root /usr/share/nginx/html; #原本这个设置是在下面localtion里面的

location / {
index index.php index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #网上很多人说这个地方有的没配置,但是我是按照php官方的来配置的,就有这个
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}


}

nginx主配置文件:

user  www-data www-data;     #用户组,要和php-fpm里面一致
worker_processes 1;

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


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

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

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf; #注意看这里,引用虚拟机配置文件
}

就这样就成了。

虚拟主机也可以下面这样配置:

server{
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php;
location ~ .*.php?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
index index.php index.html;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
}
}

效果一样,但是这种可以配合框架使用。自动分理出模块控制器和方法。