首先我们先看下Yii2高等运用程序模板的目录构造,如下图所示:
第一步:须要把网址的运行目录指向 frontend/web 文件。这样就能 http://localhost 访问到前台。下面步骤就办理怎么访问后台。
第二步:在frontend/web目录下面建一个文件夹admin。把原来在backend/web下面的文件迁移到admin下面。

第三步:修正frontend/web/admin 目录下面的index.php文件,内容如下:
<?phpdefined('YII_DEBUG') or define('YII_DEBUG', true);defined('YII_ENV') or define('YII_ENV', 'dev');require __DIR__ . '/../../../vendor/autoload.php';require __DIR__ . '/../../../vendor/yiisoft/yii2/Yii.php';require __DIR__ . '/../../../common/config/bootstrap.php';require __DIR__ . '/../../../backend/config/bootstrap.php';$config = yii\helpers\ArrayHelper::merge( require __DIR__ . '/../../../common/config/main.php', require __DIR__ . '/../../../common/config/main-local.php', require __DIR__ . '/../../../backend/config/main.php', require __DIR__ . '/../../../backend/config/main-local.php');(new yii\web\Application($config))->run();
第四步:浏览器输入http://localhost/admin 看是否能正常访问到后台。Nginx做事器须要配置伪静态:
location / { #Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args;}#If you want a single domain name at the front and back endslocation /admin { try_files $uri $uri/ /admin/index.php$is_args$args;}
详细案例可以参考:http://test.shopwind.nethttp://test.shopwind.net/admin
案例源码下载:https://gitee.com/shopwind/yii2-shopwind