17

我有一server台机器,我正在尝试允许我的 PC ip 地址使用gii

我的电脑ip地址是192.168.1.101

机器serverip是。192.168.1.102

composer以前是安装的gii module

这是我的composer.json设置的样子:

"require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "yiisoft/yii2-gii": "*"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    },

我用过php initcomposer updatephp yii migrate

我也登录了frontend

这是main.php文件内容:

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['gii'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
    ],
    'params' => $params,
    'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.1.101'],
            'password' => '123456'
        ],
    ],
];
4

8 回答 8

31

我遇到了类似的问题并尝试了所有不同的 ipFilter 更改。最后我需要将它添加到 main-local.php。这很奇怪,因为我有一个高级应用程序,并且设置是针对“yii2 基本”设置的。
http://www.yiiframework.com/doc-2.0/guide-start-gii.html

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

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';}

我还应该指出,我确实将它添加到 main.php

    'modules' => [
    'gii' => [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.1.*', 'XXX.XXX.XXX.XXX'] // adjust this to your needs
    ],
],
于 2014-11-06T11:52:14.940 回答
18

dev模式下初始化后,我必须更改我的\backend\config\main-local.php并添加“allowedIPs”。

允许所有IP,因此仅推荐用于内部开发人员使用!根据您的需要进行调整。

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['*'],
];
于 2016-02-03T11:06:25.523 回答
9

更改您的 /common/config/main-local.php 如下:

    return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=YourDatbase',
            'username' => 'YourDBUserName',
            'password' => 'YourDBPassword',
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
    ],
    // Add this to get debug and gii to work
    'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
             // permits any and all IPs
             // you should probably restrict this
            'allowedIPs' => ['*']
        ],
        'debug' => [
            'class' => 'yii\debug\Module',
             // permits any and all IPs
             // you should probably restrict this
            'allowedIPs' => ['*']
        ]
    ]
];
于 2016-03-25T17:27:34.600 回答
7

在当前版本的 Yii 中,你应该在 web.php 中这样做以允许访问 Gii:

//$config['modules']['gii'] = 'yii\gii\Module'; // <--- replace this line
$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['XXX.XXX.XXX.XXX', 'YYY.YYY.YYY.YYY']
];
于 2015-04-16T18:27:31.963 回答
5

在 if part::

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

     $config['bootstrap'][] = 'gii';
     $config['modules']['gii'] = [
          'class' => 'yii\gii\Module',
     ];
     $config['modules']['gii']['allowedIPs'] = ['*'];

 }
于 2017-10-09T17:38:38.817 回答
2

如有疑问,请检查日志。那里有一个警告应该告诉你类似的东西

10  06:00:19.040    warning yii\gii\Module::checkAccess Access to Gii is denied due to IP address restriction. The requested IP is 127.0.0.1
11  06:00:19.041    error   yii\web\HttpException:403   exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to access this page.' in ......./html/vendor/yiisoft/yii2-gii/Module.php:112

可能你对IP的看法是错误的。我刚刚尝试了您的配置,它对我有用。

PS1:您不应该在服务器上启用 Gii,但我假设您已经知道,这仍然是开发环境。

PS2:Yii2中没有设置gii的密码

于 2014-10-13T06:08:44.707 回答
1

我找到了答案,这应该被 yii 团队有据可查!

在我使用init命令后,在 中/frontend/config/main-local.php,我发现:

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

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\gii\Module';
}

我的应用程序处于dev模式,并且上面的声明停止了我gii的工作,所以...评论该行

于 2014-11-07T19:42:24.877 回答
-1

我必须将此添加到我的模块配置中

'gii' => array(
        'generatorPaths' => array('bootstrap.gii'),
        'class' => 'system.gii.GiiModule',
        'password' => 'aaa123',
        // If removed, Gii defaults to localhost only. Edit carefully to taste.
        'ipFilters' => array('*'),
    ),
于 2018-05-21T21:29:04.557 回答