yii2 学习历程——gii配置外部用户访问权限问题

本文介绍了如何配置Yii2框架中的Gii模块以允许外部PC访问。通过在配置文件config/main-local.php中设置allowedIPs参数,可以指定允许访问Gii模块的IP地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     今天尝试在家里连接公司外部服务器的yii框架的gii功能,提示 

Forbidden (#403)

You are not allowed to access this page.    

      于是花了较长的时间在百度和论坛上寻找yii2 外部pc端访问gii功能时的配置方法, 大多都是说需要找到main.php文件,然后改变默认的ip访问地址(127.0.0.1)实现, 但是找了半天无果。 自己官网文档找了好久解决方案如下:

     在文件vendor\yiisoft\yii2-gii\Module.php 中

    /**
     * @var array the list of IPs that are allowed to access this module.
     * Each array element represents a single IP filter which can be either an IP address
     * or an address with wildcard (e.g. 192.168.0.*) to represent a network segment.
     * The default value is `['127.0.0.1', '::1']`, which means the module can only be accessed
     * by localhost.
     */
    public $allowedIPs = ['115.123.134.185(替换为你现在的电脑ip)', '::1']; 

    解决了一个小问题。

   2016-07-13 更正: 本着不随意修改源码的原则, 直接在配置文件进行配置修改;

  修改如下:

   在config/main-local.php中加入:

'allowedIPs' => ['127.0.0.1', '::1','*'], // 这里允许所有用户加载gii

详细如下:

if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1','*'], // 这里允许所有用户加载gii
    ];
}

转载于:https://my.oschina.net/u/2503185/blog/537093

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值