laravel - nginx php failed to reference the outer file in the root directory
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-08 11:01:55
0
3
1044

Configure nginx.conf subdomain website for laravel and point the root directory to public
server {

    listen       80;
    server_name    local.com ;
    root  /home/wwwroot/default/laravel/public/;
    
    include enable-php.conf;

    
    index index.php index.html index.htm;
    
    location / {
        #index index.php index.html index.htm;    
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    access_log  /home/wwwlogs/access.log;

}

laravel public's index.php will require some files
require __DIR__.'/../bootstrap/autoload.php';
references files outside the subdomain directory

It will appear when accessing local.com
local.com is currently unable to handle this request.
HTTP ERROR 500

But when I visit http://127.0.0.1/laravel/public/, it is a normal visit

laravel File permissions
drwxr-xr-x 6 www www 4096 May 11 20:42 app
-rwxr-xr-x 1 www www 1646 May 11 20:42 artisan
drwxrwxrwx 3 www www 4096 May 11 20:42 bootstrap
-rw-r--r-- 1 www www 1300 May 11 20:42 composer.json
-rw-r--r-- 1 www www 122597 June 7 10:18 composer.lock
drwxr-xr-x 2 www www 4096 May 11 20:42 config
drwxr-xr-x 5 www www 4096 May 11 20:42 database
-rw-r--r-- 1 www www 1062 May 11 20:42 package.json
-rw-r--r-- 1 www www 1055 May 11 20:42 phpunit.xml
drwxrwxrwx 4 www www 4096 June 7 10:49 public
-rw-r--r-- 1 www www 3420 May 11 20:42 readme.md
drwxr-xr-x 5 www www 4096 May 11 20:42 resources
drwxr-xr-x 2 www www 4096 May 11 20:42 routes
-rw-r--r-- 1 www www 563 May 11 20:42 server .php
drwxrwxrwx 5 www www 4096 May 11 20:42 storage
drwxr-xr-x 4 www www 4096 May 11 20:42 tests
drwxrwxrwx 31 www www 4096 June 7 10:18 vendor
-rw-r--r-- 1 www www 555 May 11 20:42 webpack.mix.js

I think the problem should be that php prohibits referencing files outside the root directory
or nginx prohibits accessing files outside the root directory
or? ? ? ? ?
Looking for a solution?

I found the reason myself but still have no solution

Display results

The source code of the laravel framework when the code is definitely OK
The main reason should be that outer files cannot be referenced

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
给我你的怀抱

Introduce this file into nginx.conf include fastcgi.conf;

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/home/wwwroot/default/laravel/";
Add the outer folder directory you want to reference, and this problem will be solved, mom The laravel framework doesn't care about this, which causes this kind of problem. Anyway, I encountered this problem and there is no place to search for it

左手右手慢动作

Look at the nginx error log, any error like 500 is possible

習慣沉默

It’s not a problem with nginx, nor is it a problem with permissions. Files outside the directory like yours cannot be obtained.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template