您的位置:首页 > 编程语言 > PHP开发

yii2 gii Forbidden (#403)解决方案

2015-10-23 17:47 1056 查看
原文章来自
it技术擎


Forbidden (#403)          

 You are not allowed to access this page.    

            The above error occurred while the Web server was processing your request.    
            Please contact us if you think this is a server error. Thank you.
如果出到以上的错误,请确认你的配置是否是正确的。
$config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = array('class'=>'yii\gii\Module',    
原始 的配置是这样的,如果你的 使用的是本地的服务器的话,则不会存在问题。
如果你使用的是服务器的问题,就会出现以上的错误提示了
详细分析得知,是Gii做了默认IP限定了
源代码如下:
namespace yii\gii;

use Yii;
use yii\base\BootstrapInterface;
use yii\web\ForbiddenHttpException;
class Module extends \yii\base\Module implements BootstrapInterface
{
public $controllerNamespace = 'yii\gii\controllers';
public $allowedIPs = ['127.0.0.1', '::1'];
。。。。。。
源代码做了限定了  只允许  127.0.0.1是可以访问的其他都是不行的。

所以解决以上的问题
需要修改配置如下:
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = array('class'=>'yii\gii\Module',
                                        'allowedIPs' => ['127.0.0.1', '::1', '192.168.*.*', '192.168.178.20'],
                                        );
这样在 allowedIPs  数组里面的IP全部可以访问了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: