doushu2699 2019-07-19 14:22
浏览 106
已采纳

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

  • 写回答

1条回答 默认 最新

  • duanli5662 2019-07-19 14:48
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 mysql报错1415Not allowed to return a result set from a trigger 不知如何修改
    • ¥60 Python输出Excel数据整理,算法较为复杂
    • ¥15 看一下这个,可以商量
    • ¥15 回答几个问题 关于数据库
    • ¥15 设计程序(标签-STM32|关键词-工作模式)
    • ¥15 51单片机串口通信问题,未完成且要修改
    • ¥15 百鸡问题 c++编程问题(相关搜索:输出数据)
    • ¥30 如何在CMD中设置代理
    • ¥15 我有一块薛定谔的硬盘
    • ¥15 微信小游戏开发2D碰撞检测问题