Yii2 Gii禁止代码403您无权访问此页面

Ion*_*ian 15 php gii yii2

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

我的电脑IP地址是 192.168.1.101

server机的ip是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": "*"
    },
Run Code Online (Sandbox Code Playgroud)

我已经使用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'
        ],
    ],
];
Run Code Online (Sandbox Code Playgroud)

joh*_*ils 27

我遇到了类似的问题并尝试了所有不同的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';}
Run Code Online (Sandbox Code Playgroud)

我还应该指出,我确实将它添加到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
    ],
],
Run Code Online (Sandbox Code Playgroud)

  • 当我将应用程序上传到生产服务器时,我遇到了类似的问题,看起来如果你没有在 `$config['modules']['debug'] = [` 它 **defaults to localhost** 中指定 `allowedIPs`,所以我无法访问生产调试,通过添加“allowedIPs”解决 (2认同)

mfg*_*cha 16

在初始化dev模式后,我不得不改变我的\backend\config\main-local.php并添加'allowedIPs'.

允许所有 IP,因此仅建议内部开发人员使用!根据您的需求调整.

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['*'],
];
Run Code Online (Sandbox Code Playgroud)


小智 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']
];
Run Code Online (Sandbox Code Playgroud)


小智 6

更改您的/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' => ['*']
        ]
    ]
];
Run Code Online (Sandbox Code Playgroud)


RAP*_*POS 5

在 if 部分内的 YII_ENV_DEV 之前添加感叹号(!)后,该代码对我有用(yii 2.0.8):

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'] = ['*'];

 }
Run Code Online (Sandbox Code Playgroud)