草庐IT

php - Yii2 Gii Forbidden code 403 You are not allowed to access this page

coder 2023-06-15 原文

我有一台服务器机器,我试图让我的PC ip地址使用gii

我的电脑 IP 地址是 192.168.1.101

服务器机器ip是192.168.1.102

我使用 composer 安装了 gii 模块

这是我的 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 update 以及 php yii migrate

我也登录了前端

这是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'
        ],
    ],
];

最佳答案

我遇到了类似的问题并尝试了所有不同的 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
    ],
],

关于php - Yii2 Gii Forbidden code 403 You are not allowed to access this page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26315808/

有关php - Yii2 Gii Forbidden code 403 You are not allowed to access this page的更多相关文章

随机推荐