php - 找不到文件 nginx php-fpm

标签 php nginx

我已经仔细查看了这里的每个问题,并尝试应用规定的修复程序但没有成功。

我正在使用 wordpress:4.7.3-php7.0-fpm-alpine docker 图像,前面有一个单独的 nginx 容器。

当我 curl wordpress 时,我得到:

File not found.

当我检查 wordpress 容器日志时,我得到:

127.0.0.1 -  16/Mar/2017:06:26:24 +0000 "GET /index.php" 404
127.0.0.1 -  16/Mar/2017:06:31:27 +0000 "GET /index.php" 404
127.0.0.1 -  16/Mar/2017:06:32:16 +0000 "GET /index.php" 404
127.0.0.1 -  16/Mar/2017:06:37:17 +0000 "GET /index.php" 404
127.0.0.1 -  16/Mar/2017:06:39:09 +0000 "GET /index.php" 404

实际的nginx错误是:

2017/03/16 06:26:24 [error] 17#17: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.128.0.7, server: k8wp, request
: "GET / HTTP/1.0", upstream: "fastcgi://127.0.0.1:9000"

我正在使用 php 7

/var/www/html # php-fpm -v
PHP 7.0.16 (fpm-fcgi) (built: Mar  3 2017 23:07:56)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.16, Copyright (c) 1999-2017, by Zend Technologies

我的nginx配置是

server {
    root /app;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.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;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    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;
    }
}

我正在以用户 www-data 的身份运行 nginx:

user www-data;

根据 /usr/local/etc/php-fpm.d/www.conf 用户和组取消注释并设置为 www-data

最佳答案

该错误表明您的 SCRIPT_FILENAME 不正确。您的评论:

in the wordpress container it's at /var/www/html/index.php in the nginx container it's at /app

表明 nginxphp-fpm 正在查看不同的文档根目录。

在这种情况下,使用:

fastcgi_param   SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;

关于php - 找不到文件 nginx php-fpm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42827222/

相关文章:

php generate date/time in the same format 出现在 mysql datetime

php - 日期时间差异阴性结果?

php - 在数学运算中使用 PHP preg_replace 匹配结果?

单击后将 Javascript var 转换为 php

php - 无法在 .htaccess 中为我的 php 网站编写重写规则

ruby-on-rails - Rails API 404 错误 - 使用 Capistrano、Nginx 和 Passenger 部署

nginx - 如何判断我的服务器是否正在提供 GZipped 内容?

php - 在 Nginx 中通过 phpmyadmin 将 20mb SQL 文件导入 MySQL 时出现 “connection was reset”

php - 502 网关错误 - PHP 7、Nginx、Centos

ruby-on-rails - 如何限制 ruby​​ 对 Passenger/NGINX 的 CPU 使用?