nginx和php-fpm之间是怎样通信的?
怪我咯
怪我咯 2017-04-10 15:26:47
0
5
281
server {

root /srv/www;

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

location ~ \.php$ {

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name;
            include        fastcgi_params;
        }

}

在目录/srv/www中有index.html index.php 两个文件,访问localhost/index.html ,localhost 能够正常显示/srv/www/index.html页面的内容,但是访问index.php文件却显示File Not Found,不知到是怎么回事?在这种情况下难道nginx不是应该将/srv/www/index.php文件先传送给监听在127.0.0.1:9000的php解析器,然后通过其解析后返回解析器的内容给客户端吗?不知到哪里的问题,希望帮忙解答下

怪我咯
怪我咯

走同样的路,发现不同的人生

membalas semua(5)
大家讲道理

估计是你nginx的fpm的配置问题。
我这边这样搞的,已经用过好多个网站了:

server {
        listen   80; ## listen for ipv4; this line is default and implied

        root /www/web;
        index index.html index.htm index.php;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}
小葫芦

看看fpm错误日志,分分钟定位问题啊!

伊谢尔伦
location / {
    index  index.php index.html index.htm;
}

index 中需要加上index.php 优先识别最前面的文件

大家讲道理

问题出在这里:

server {

root /srv/www;#srv目录

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

location ~ \.php$ {

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name; #src目录
            include        fastcgi_params;
        }

}

另外:
下面那部分这样写最好:

location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
#        fastcgi_pass unix:/var/run/php5-fpm.sock;#这行和上面一行二选一。
        fastcgi_index index.php;
        include fastcgi_params;
}
Ty80

你的php-fpm起了吗?监听的是9000端口吗

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan