繁体   English   中英

找不到文件 nginx php-fpm

[英]File not found nginx php-fpm

我已经在这里查看了这样的每个问题,并尝试应用所述修复程序但没有成功。

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

当我卷曲 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不正确。 你的评论:

在 wordpress 容器中它位于 /var/www/html/index.php 在 nginx 容器中它位于 /app

表明nginxphp-fpm看到的是不同的文档根目录。

在这种情况下,请使用:

fastcgi_param   SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;

您可以尝试包含include snippets/fastcgi-php.conf; . 它应该可以解决您的问题。

我遇到的问题是我的 wordpress 安装在一个子目录中。 因此,wordpress 的 /blog/ 主索引将加载,但不会加载任何已发布的博客条目或更深目录(例如/blog/wp-admin/

为了解决这个问题,我添加了这个块:

location /blog {
                try_files $uri $uri/ /blog/index.php?$args;
        }

这实际上在nginx wordpress recipes page 的“位置策略”中有解释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM