不能发文章,我只能发问题了。laravel 在nginx中报错 open_basedir restriction in effect. 问题解答

首先以普遍的方式解答这个错误的原因

open_basedir restriction in effect 这个错误,不容置疑是open_basedir这个配置阻止了继续访问。

方法1)在Nginx配置文件中加入
fastcgi_param PHP_VALUE “open_basedir=$document_root:/tmp/:/proc/”;
通常nginx的站点配置文件里用了include fastcgi.conf;,这样的,把这行加在fastcgi.conf里就OK了。
如果某个站点需要单独设置额外的目录,把上面的代码写在include fastcgi.conf;这行下面就OK了,会把fastcgi.conf中的设置覆盖掉。
这种方式的设置需要重启nginx后生效。

方法2)在php.ini中加入:
[HOST=www.test.com]
open_basedir=/home/www/www.test.com:/tmp/:/proc/
[PATH=/home/www/www.test.com]
open_basedir=/home/www/www.test.com:/tmp/:/proc/

这种方式的设置需要重启php-fpm后生效。

方法3)在网站根目录下创建.user.ini并写入:
open_basedir=/home/www/www.test.com:/tmp/:/proc/

这种方式不需要重启nginx或php-fpm服务。安全起见应当取消掉.user.ini文件的写权限。
关于.user.ini文件的详细说明:
http:// php.net /manual/zh/configuration.file.per-user.php

这个时候,你发现还是报错,那么问题来了。都配置好了,为何还会报错呢?那是因为我们根目录host指向了public/*

而nginx配置内是这样写的
fastcgi_param PHP_VALUE “open_basedir=$document_root:/usr/share/pear:/usr/share/php:/etc/phpMyAdmin:/tmp:/proc”;

虽然不懂nginx 但这个 $document_root 变量应该是获取当前目录。当你访问首页的时候这个变量会是 ../public 的目录,然后public的目录没有在open_basedir 内,所以报错说不在范围内。

我是这样做的
fastcgi_param PHP_VALUE “open_basedir=$document_root:/home/wwwroot/testdir:/usr/share/pear:/usr/share/php:/etc/phpMyAdmin:/tmp:/proc”;

有什么问题可以下方留言。
已邀请:

要回复问题请先登录注册