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

SOLVED: File was not correctly named (header.php instead of layout.php)

I'm currently experimenting with NGINX and PHP. I try to require some files, but unfortuantely require is only looking for things like this: /path/to/root/subdir/index.php

The relevant part of the configuration is the PHP Playground Area. Please have a look. Is there something wrong with the config, so that it is just looking for index.php files for includes with PHP?

The nginx error log just displays: 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

I checked my structure. The required layout.php file is placed in the same directory under var/www/html/php.

Code where I try to require:

<?php

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

echo "Hello World";

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

Config:

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?/$1 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;
}

}

File structure:

/var/www/html -> laravel part and php playground /var/www/wordpress -> wordpress part

structure of the html directory

dppxp79175
dppxp79175 它发生的事情比你认为的更多:)有时它真的有助于真正把它分解成真正看到问题的愚蠢事物
一年多之前 回复
duanpan7011
duanpan7011 如果您已经解决了问题,请发布回答并接受或删除问题。我们在这里的标题中没有“解决”
一年多之前 回复
dongtang4954
dongtang4954 天啊。对我感到羞耻。那就是问题所在。应该停止今天的工作。非常感谢你们
一年多之前 回复
dtl19910708
dtl19910708 正如treyBake指出的那样,你的截图最终表明php文件夹中没有layout.php。
一年多之前 回复
doudiemei2013
doudiemei2013 layout.php的权限设置为rwxforgroup(www-data)和owner(www-data)。nginx和phpfpm拥有相同的用户
一年多之前 回复
dougu1952
dougu1952 我没有在那里看到layout.php文件?o.O
一年多之前 回复
douzhe9927
douzhe9927 在nginx中404==403?o.O
一年多之前 回复
dou448172583
dou448172583 结构附加。
一年多之前 回复
douhe1002
douhe1002 检查/var/www/html/php/layout.php的权限。不只是它的存在。
一年多之前 回复
douguio0185
douguio0185 并且是额外的迂腐-你可以截取文件树(或树的相关部分)
一年多之前 回复
dqxmf02844
dqxmf02844 我将代码附加到帖子上。
一年多之前 回复
douci2022
douci2022 我也不会嵌套〜\.php{}部分,因为它使配置的可读性低得多。我想它会让你在phpplayground部分看到你没有try_files。
一年多之前 回复
dsbqfrr098575666
dsbqfrr098575666 错误=404.找不到您尝试传递的文件(无论是否与nginx相关)。可以肯定的是,您是否可以包含满足要求的代码?
一年多之前 回复

1个回答



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

由于treyBake发现文件未正确命名。 我没有使用header.php而是使用layout.php。</ p>
</ div>

展开原文

原文

SOLVED: File was not correctly named (header.php instead of layout.php)

As treyBake discovered the file was not named correctly. Instead of header.php I used layout.php.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐