FastCGI sent in stderr: "Primary script unknown" while reading

多容器搭建 php-fpm + nginx, 在测试 nginx 的配置是否成功与 fpm 连通时,访问 url,

每次都报 File not found.

nginx 的日志如下:

clipboard.png

核心的问题: FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

docker logs php-fpm 的日志如下:

clipboard.png

nginx 的日志如下:

server {
    listen       80;
    server_name  localhost;
    root /usr/share/nginx/html/;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        fastcgi_pass   php_180227_7.1.0:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }
}

nginx 的共享目录如下(/home/docker_lnmp/nginx/www:/usr/share/nginx/html):

clipboard.png

php 的共享目录如下(/home/docker_lnmp/nginx/www:/var/www/html):

clipboard.png

阅读 17.4k
2 个回答

nginx 配置文件 config

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

要换成

fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;

不然 php fastcgi解析不了目录

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏