错误28105#0:*1 stderr发送的FastCGI:从上游读取响应头时"主脚本未知"

Vic*_*sky 6 php virtualhost nginx docker

我不能配置Nginxphp-fpm正确.当我得到任何PHP脚本时,我404 Not found在浏览器中收到Nginx 错误:

File not found.
Run Code Online (Sandbox Code Playgroud)

在我的php-fpm日志中,我得到:

172.17.42.1 -  28/Apr/2015:09:15:15 +0000 "GET /index.php" 404
Run Code Online (Sandbox Code Playgroud)

任何PHP脚本调用和Nginx日志我得到:

[error] 28105#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.168.66.66:9000", host: "localhost"
Run Code Online (Sandbox Code Playgroud)

我的Nginx vitualhost配置是:

server {
  listen 80;

  root /var/www/html;
  index index.html;

  server_name localhost;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
  }

  location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.168.66.66:9000;
    #fastcgi_pass    unix:/var/run/php5-fpm.sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
  }
}
Run Code Online (Sandbox Code Playgroud)

我从官方的php存储库中运行php-fpm Docker镜像,运行方式为:

docker run -it -p 127.168.66.66:9000:9000 php:fpm
Run Code Online (Sandbox Code Playgroud)

docker ps命令显示下一个信息:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                          NAMES
dbf9f7d1c6f9        php:fpm             "php-fpm"           8 seconds ago       Up 7 seconds        127.168.66.66:9000->9000/tcp   serene_curie 
Run Code Online (Sandbox Code Playgroud)

我的配置有什么问题?

PS任何静态文件(css,js,images)都适用于Nginx.

Vic*_*sky 8

此外,还需要将文件共享到php:fpmdocker容器.答案是php:fpm使用卷运行docker 镜像:

docker run -it -p 127.168.66.66:9000:9000 -v /var/www/html/:/var/www/html/ php:fpm
Run Code Online (Sandbox Code Playgroud)