关于thinkPHP5部署nginx 伪静态配置 tp5部署nginx

第一个问题:

Warning: require(): open_basedir restriction in effect. File(/mnt/wwwroot/admincc/thinkphp/start.php) is not within the allowed path(s): (/mnt/wwwroot/admincc/public/:/tmp/:/proc/) in /mnt/wwwroot/admincc/public/index.php on line 17

Warning: require(/mnt/wwwroot/admincc/thinkphp/start.php): failed to open stream: Operation not permitted in /mnt/wwwroot/admincc/public/index.php on line 17

Fatal error: require(): Failed opening required '/mnt/wwwroot/admincc/public/../thinkphp/start.php' (include_path='.:/usr/local/php/lib/php') in /mnt/wwwroot/admincc/public/index.php on line 17

这个是打开php错误提示后显示的错误信息(如果不打开提示,浏览器只会显示500错误,不便于排查。)

解决办法:

出现这种错误主要受fastcgi.conf中open_basedir参数控制,在我的配置文件中,这个参数的默认值是这样的:

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

open_basedir参数的作用就是将php能打开的文件限制在特定的目录树中,默认的$document_root是nginx.conf中配置的/home/wwwroot/default目录,而我项目的目录是在/mnt/wwwroot/admincc/public下,由于项目目录没有包含在open_basedir中,因此会报如上的错,解决方法也就很简单了,将项目家目录加入即可。

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/mnt/wwwroot:$document_root/:/tmp/:/proc/";

PS:还有一种解决方法是直接把这个参数注释掉。

第二个问题:

错误提示:

scandir() has been disabled for security reasons

错误提示是说scandir函数因为安全原因被禁用了。

解决办法:

没错,就像它提示的这个函数默认在php.ini中是禁用的。

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

很明显,scandir被禁用了,解决方法也简单,把scandir删掉,重启php-fpm就好。

service php-fpm restart

第三个问题:

访问报404错误。

解决办法:

这个的原因在于nginx的配置有问题,在vhost/admincc.conf(站点虚拟主机的配置文件)中添加如下配置即可:

location / {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
        }

由于ThinkPHP的入口文件是index.php,所以要重写下url。
保存配置,记得重启nginx。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值