网站首页 > 技术教程 正文
用Yii2高级应用程序模板搭建的系统,根目录设置为wwwroot,访问路径是这样的,前台访问路径:http://localhost/frontend/web, 后台访问路径:http://localhost/backend/web, 这样的访问不是很方便。那么怎么样才能修改为 http://localhost 和 http://localhost/admin 这样的访问路径呢?
首先我们先看下Yii2高级应用程序模板的目录结构,如下图所示:
第一步:需要把网址的运行目录指向 frontend/web 文件。这样就能 http://localhost 访问到前台。下面步骤就解决怎么访问后台。
第二步:在frontend/web目录下面建一个文件夹admin。把原本在backend/web下面的文件迁移到admin下面。
第三步:修改frontend/web/admin 目录下面的index.php文件,内容如下:
<?php
defined('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 ends
location /admin {
try_files $uri $uri/ /admin/index.php$is_args$args;
}
具体案例可以参考:
http://test.shopwind.net
http://test.shopwind.net/admin
案例源码下载:https://gitee.com/shopwind/yii2-shopwind
猜你喜欢
- 2024-10-15 架构师之必杀技——反向代理&负载均衡器
- 2024-10-15 面试腾讯、字节等大厂后,我总结一份面试文档给大家参考
- 2024-10-15 swoole运行模式加速laravel应用的详细介绍
- 2024-10-15 (PHP)开发Laravel扩展的基本流程(laravel php artisan)
- 2024-10-15 「PHP 技巧」 不要直接克隆对象,请使用深拷贝
- 2024-10-15 Yii2负载均衡必备:MD4文件缓存技巧
- 2024-10-05 网站跨域的五种解决方式(浏览器解决跨域)
- 2024-10-05 用户登录实现(登录功能实现)
- 2024-10-05 使用kubeadm部署Kubernetes 1.22(kubeedge部署)
- 2024-10-05 PHP性能全面优化-值得收藏(php性能调优工具)
你 发表评论:
欢迎- 最近发表
-
- 阿里P8大佬总结的Nacos入门笔记,从安装到进阶小白也能轻松学会
- Linux环境下,Jmeter压力测试的搭建及报错解决方法
- Java 在Word中合并单元格时删除重复值
- 解压缩软件哪个好用?4款大多数人常用的软件~
- Hadoop高可用集群搭建及API调用(hadoop3高可用)
- lombok注解@Data没有toString和getter、setter问题
- Apache Felix介绍(apache fineract)
- Spring Boot官方推荐的Docker镜像编译方式-分层jar包
- Gradle 使用手册(gradle详细教程)
- 字节二面:为什么SpringBoot的 jar可以直接运行?
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)