require() 不工作 - NGINX PHP 配置问题

require() not working - NGINX PHP configuration problem

已解决:文件未正确命名(header.php 而不是 layout.php)

我目前正在试验 NGINX 和 PHP。我尝试要求一些文件,但不幸的是要求只是寻找这样的东西:/path/to/root/subdir/index.php

配置的相关部分是PHP游乐场。请看一看。配置有问题吗,所以它只是在寻找 index.php 文件以包含 PHP?

nginx错误日志显示:FastCGI sent in stderr: "PHP message: PHP Warning: require(layout.php): failed to open stream: No such file or directory in /var/www/html/php/index.php on line 7

我检查了我的结构。需要的layout.php文件放在同目录下var/www/html/php.

我尝试要求的代码:

<?php

echo "<title>Playground</title>";

echo "Hello World";

require('layout.php');
require ('footer.php');

配置:

server {

# ======================
# BASIC CONFIGURATION
# ======================

listen 80;
server_name 172.17.1.75;
root /var/www/wordpress/;
index index.php index.html index.htm;
#try_files $uri $uri/ /index.php$is_args$args;
try_files $uri $uri/ /index.php?$query_string;

error_log /var/log/nginx/error.log info;
rewrite_log on;

# ======================
# WORDPRESS WEBSITE
# ======================

location / {
    # pass PHP scripts to FastCGI server
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

# ======================
# PHP PLAYGROUND
# ======================

location /php {
root /var/www/html/;
# pass PHP scripts to FastCGI server
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

# ======================
# ORDER PORTAL
# ======================

location ^~ /laravel {
alias /var/www/html/public;
try_files $uri $uri/ @laravel;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

}

location @laravel {
    rewrite /laravel/(.*)$ /laravel/index.php?/ last;
}

# ======================
# PROXY PASS AREA
# ======================

# Proxy to holiday and work time management
location /azm {
    proxy_pass http://172.17.1.28:8081;
}

# Proxy to old shop
location /shop2 {
    proxy_pass http://172.17.1.28:8080;
}

# Proxy to order portal without laravel
location /portal {
    proxy_pass http://172.17.1.28;
}

}

文件结构:

/var/www/html -> laravel 部分和 php 操场 /var/www/wordpress -> wordpress 部分

已解决:文件未正确命名(header.php 而不是 layout.php)

正如 treyBake 发现的那样,文件命名不正确。我使用 layout.php.

而不是 header.php