yii2 gii Forbidden (#403)解决方案

原文章来自 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全部可以访问了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值