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.

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

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容